1.8 Inserting, updating, and deleting rows Flashcards
INSERT
The INSERT statement adds rows to a table.
INSERT TableName (Column1, Column2, …)
INSERT INTO
The INSERT INTO clause names the table and columns where data is to be added. The keyword INTO is optional.
If all columns are added, as long as they are listed in order, the column names are optional. EX: if there is an auto incremented column, since this one cannot be added, you have to list the column names.
INSERT [INTO] TableName (Column1, Column2, …)
VALUES (Column1Val, Column2Val, …)
VALUES clause
The VALUES clause specifies the column values to be added.
Column names can be omitted as long as the VALUES clause lists all column values in the table’s column order
This
INSERT INTO Employee (ID, Name, Salary)
VALUES (2538, ‘Lisa Ellison’, 45000);
Turns to this:
INSERT INTO Employee
VALUES (5384, ‘Sam Snead’, 30500);
DEFAULT
The optional DEFAULT keyword and default value follow the column name and data type in a CREATE TABLE statement. The column is assigned the default value, rather than NULL, when omitted from an INSERT statement.
BirthDate DATE DEFAULT ‘2000-01-01’
UPDATE
The UPDATE statement modifies existing rows in a table.
UPDATE TableName
SET Column1 = Value1, Column2 = Value2, …
WHERE condition;
SET
The UPDATE statement uses the SET clause to specify the new column values.
DELETE
The DELETE statement deletes existing rows in a table.
FROM
The FROM keyword is followed by the table name whose rows are to be deleted.
TRUNCATE
The TRUNCATE statement deletes all rows from a table.