constraints Flashcards
Restricts NULL value from being inserted into a column
NOT NULL
Verifies that all values in a field satisfy a condition
CHECK
Automatically assigns a default value if no value has been specified for the field
DEFAULT
Ensures unique values to be inserted into the field
UNIQUE
Indexes a field providing faster retrieval of records
INDEX
Uniquely identifies each record in a table
PRIMARY KEY
Ensures referential integrity for a record in another table
FOREIGN KEY
Create table with multiple fields as primary ke
CREATE TABLE Students ( ID INT NOT NULL LastName VARCHAR(255) FirstName VARCHAR(255) NOT NULL, CONSTRAINT PK_Student PRIMARY KEY (ID, FirstName) );
Set multiple columns as primary key
ALTER TABLE Students
ADD CONSTRAINT PK_Student
PRIMARY KEY (ID, FirstName);
Set a column as primary key
ALTER TABLE Students
ADD PRIMARY KEY (ID);
Create table with multiple fields as unique
CREATE TABLE Students ( ID INT NOT NULL LastName VARCHAR(255) FirstName VARCHAR(255) NOT NULL CONSTRAINT PK_Student UNIQUE (ID, FirstName) );
Create index
CREATE INDEX index_name ON table_name (column_1, column_2);
What is Data Integrity?
Data Integrity is the assurance of accuracy and consistency of data over its entire life-cycle, and is a critical aspect to the design, implementation and usage of any system which stores, processes, or retrieves data. It also defines integrity constraints to enforce business rules on the data when it is entered into an application or a database.