Key Concepts

Review core concepts you need to learn to master this subject

CREATE TABLE Statement

CREATE TABLE table_name ( column1 datatype, column2 datatype, column3 datatype );

The CREATE TABLE statement is used to create a new table in a database. It allows one to specify the name of the table and the name of each column in the table.

INSERT Statement

CREATE TABLE table_name ( column1 datatype, column2 datatype, column3 datatype );

The INSERT INTO statement is used to add a new record (row) to a table.

It has two forms as shown in the code block:

  • Insert values based on the order of the columns in the table.
  • Define the columns to insert values into.

UPDATE Statement

CREATE TABLE table_name ( column1 datatype, column2 datatype, column3 datatype );

The UPDATE statement is used to edit records (rows) in a table. It usually includes a SET clause that indicates the column to edit and a WHERE clause for specifying which record(s) should be updated.

ALTER TABLE Statement

CREATE TABLE table_name ( column1 datatype, column2 datatype, column3 datatype );

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

DELETE Statement

CREATE TABLE table_name ( column1 datatype, column2 datatype, column3 datatype );

The DELETE statement is used to delete records (rows) in a table. This statement does not delete the whole table.

Inside, the WHERE clause specifies which record or records that should be deleted. If the WHERE clause is omitted, all records will be deleted.

Column Constraints

CREATE TABLE table_name ( column1 datatype, column2 datatype, column3 datatype );

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. 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! 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…

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