Key Concepts

Review core concepts you need to learn to master this subject

Column Constraints in SQL

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

SQL column constraints are the rules that you can apply on values of individual columns.

Some of the available constraints in SQL are:

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

CREATE TABLE Statement in SQL

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

The CREATE TABLE statement is used to create new tables in a database. Column names and types are provided as a comma-separated list of values between ().

The column parameters specify the names of the columns of the table.

The datatype parameters specify the type of data the column can hold (e.g. TEXT, INTEGER, etc.).

INSERT Statement in SQL

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

The INSERT INTO statement is used to insert new records in a table.

The INSERT INTO statement has two forms as shown in the code block. You can define the columns to insert values or insert directly based on the column order.

ALTER TABLE Statement in SQL

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

The ALTER TABLE statement is used to modify an existing table. When combined with the ADD clause, it is used to add a new column definition to a table.

UPDATE Statement in SQL

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

The UPDATE statement is used to edit records (rows) in a table.

The UPDATE statement usually includes a WHERE clause for specifying which record(s) should be updated.

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. You 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 celeb 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! You’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 program…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

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

Pro Logo