INSERT INTO Statement: Used to add new rows to a table.
Syntax: INSERT INTO table_name (column1, column2,...) VALUES (value1, value2,...);
Optional Keyword: INTO
is optional in the syntax.
NULL Values: If a column is assigned a NULL value:
If the column has a NOT NULL constraint, the insert is rejected.
Default Value: A default value can be specified for columns.
Syntax: DEFAULT value
follows the keyword before the column in a CREATE TABLE
statement.
Column Assignment: When a row is added, columns without specified values get either a NULL or default value.
UPDATE Statement: Used to modify existing records in a table.
SET Clause: Specifies the new values for the columns being updated.
Example: UPDATE table_name SET column1 = value1, column2 = value2;
WHERE Clause: Optional, defines which rows are updated.
Omitting the WHERE
clause updates all rows in the table.
DELETE Statement: Used to remove rows from a table.
DELETE Syntax: DELETE FROM table_name WHERE condition;
FROM Clause: Indicates the table from which rows will be deleted.
TRUNCATE Statement: Quickly removes all rows from a table.
Syntax: TRUNCATE TABLE table_name;
Differences from DELETE:
Unlike DELETE
, does not require a WHERE clause.
Typically performed faster than DELETE, as it does not log individual row deletions in most database systems.
2.8f
INSERT INTO Statement: Used to add new rows to a table.
Syntax: INSERT INTO table_name (column1, column2,...) VALUES (value1, value2,...);
Optional Keyword: INTO
is optional in the syntax.
NULL Values: If a column is assigned a NULL value:
If the column has a NOT NULL constraint, the insert is rejected.
Default Value: A default value can be specified for columns.
Syntax: DEFAULT value
follows the keyword before the column in a CREATE TABLE
statement.
Column Assignment: When a row is added, columns without specified values get either a NULL or default value.
UPDATE Statement: Used to modify existing records in a table.
SET Clause: Specifies the new values for the columns being updated.
Example: UPDATE table_name SET column1 = value1, column2 = value2;
WHERE Clause: Optional, defines which rows are updated.
Omitting the WHERE
clause updates all rows in the table.
DELETE Statement: Used to remove rows from a table.
DELETE Syntax: DELETE FROM table_name WHERE condition;
FROM Clause: Indicates the table from which rows will be deleted.
TRUNCATE Statement: Quickly removes all rows from a table.
Syntax: TRUNCATE TABLE table_name;
Differences from DELETE:
Unlike DELETE
, does not require a WHERE clause.
Typically performed faster than DELETE, as it does not log individual row deletions in most database systems.