Column constraints are the rules applied to the values of individual columns:
PRIMARY KEYconstraint can be used to uniquely identify the row.
UNIQUEcolumns have a different value for every row.
NOT NULLcolumns must have a value.
DEFAULTassigns a default value for the column when no value is specified.
There can be only one
PRIMARY KEY column per table and multiple
CREATE TABLE statement creates 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 INTO statement is used to add a new record (row) to a table.
It has two forms as shown:
- Insert into columns in order.
- Insert into columns by name.
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.
DELETE statement is used to delete records (rows) in a table. The
WHERE clause specifies which record or records that should be deleted. If the
WHERE clause is omitted, all records will be deleted.
UPDATE statement is used to edit records (rows) in a table. It includes a
SET clause that indicates the column to edit and a
WHERE clause for specifying the record(s).
- 1SQL, 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…
- 2Nice 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…
- 3The 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, …
- 4CREATE 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…
- 5The 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. …
- 6SELECT 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 …
- 7The 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. …
- 8The 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…
- 9The 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 …
- 10Constraints 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…
- 11Congratulations! 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…