Key Concepts

Review core concepts you need to learn to master this subject

Column Constraints

CREATE TABLE student ( id INTEGER PRIMARY KEY, name TEXT UNIQUE, grade INTEGER NOT NULL, age INTEGER DEFAULT 10 );

Column constraints are the rules applied to the values of individual columns:

  • PRIMARY KEY constraint can be used to uniquely identify the row.
  • UNIQUE columns have a different value for every row.
  • NOT NULL columns must have a value.
  • DEFAULT assigns a default value for the column when no value is specified.

There can be only one PRIMARY KEY column per table and multiple UNIQUE columns.

Manipulation
Lesson 1 of 1
  1. 1
    SQL, Structured Query Language, is a programming language designed to manage data stored in relational databases. SQL operates through simple, declarative statements. This keeps data ac…
  2. 2
    Nice work! In one line of code, you returned information from a relational database. SELECT * FROM celebs; We’ll take a look at what this code means soon, for now, let’s focus on what relationa…
  3. 3
    The code below is a SQL statement. A statement is text that the database recognizes as a valid command. Statements always end in a semicolon ;. CREATE TABLE table_name ( column_1 data_type, …
  4. 4
    CREATE statements allow us to create a new table in the database. You can use the CREATE statement anytime you want to create a new table from scratch. The statement below creates a new table named…
  5. 5
    The INSERT statement inserts a new row into a table. We can use the INSERT statement when you want to add new records. The statement below enters a record for Justin Bieber into the celebs table….
  6. 6
    SELECT statements are used to fetch data from a database. In the statement below, SELECT returns all data in the name column of the celebs table. SELECT name FROM celebs; 1. SELECT is a clause …
  7. 7
    The ALTER TABLE statement adds a new column to a table. You can use this command when you want to add columns to a table. The statement below adds a new column twitter_handle to the celebs table. …
  8. 8
    The UPDATE statement edits a row in a table. You can use the UPDATE statement when you want to change existing records. The statement below updates the record with an id value of 4 to have the twit…
  9. 9
    The DELETE FROM statement deletes one or more rows from a table. You can use the statement when you want to delete existing records. The statement below deletes all records in the celebs table with…
  10. 10
    Constraints that add information about how a column can be used are invoked after specifying the data type for a column. They can be used to tell the database to reject inserted data that does no…
  11. 11
    Congratulations! We’ve learned six commands commonly used to manage data stored in a relational database and how to set constraints on such data. What can we generalize so far? SQL is a programmin…

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo