Insert, Update, Delete, RI, and Constraints Flashcards
INSERT
Adds a new row of data to a table
Can be shortened to insert every column:
INSERT INTO table_name VALUES (value1, value2, … value_n);
UPDATE
Updates the value of columns on an existing row of data for the specific rows.
UPDATE table_name
SET column = value
WHERE column = value;
Can update multiple columns in a since update statement.
UPDATE table_name
SET column1 = value1, column2 = value2
WHERE column = value;
DELETE
Deletes row(s) of data from a table. DELETE FROM table_name WHERE column=value;
Referential Integrity
Referential Integrity is a property of the data stating whether or not references within it are valid. For example, to use a foreign key on a table, the value must exist on the primary table.
Constraints
defines properties that the column data must comply with. It sets a rule that must be obeyed to maintain the integrity of the data
Constraints examples
NOT NULL UNIQUE PRIMARY KEY FOREIGN KEY CHECK DEFAULT
NOT NULL constraint
The column cannot contain a null value
UNIQUE constraint
The column can only contain unique values
PRIMARY KEY constraint
Enforces NOT NULL and UNIQUE. Allows Foreign Key relationships to be established.
FOREIGN KEY constraint
Only allows values where the value exists on the related table. Does not allow the related value to be removed from the related table as long as the foreign key value is in use.
CHECK constraint
Specifies a list of acceptable values that can be added into a column
DEFAULT constraint
Provides a default value for a column, if no value is provided.
Transactions
a single unit of work made up of multiple SQL statements that must all succeed or fail as one
When a transaction is successful it is
committed and the data is saved in the new state
When a transaction fails it is
rolled back and all the data is left in the original state.