|
Answer» The PRIMARY KEY constraint uniquely identifies each row in a table. It must contain UNIQUE values and has an implicit NOT NULL constraint. A table in SQL is strictly restricted to have one and only one primary key, which is comprised of single or MULTIPLE fields (columns). CREATE TABLE Students ( /* Create table with a single field as primary key */ ID INT NOT NULL Name VARCHAR(255) PRIMARY KEY (ID));CREATE TABLE Students ( /* Create table with multiple fields as primary key */ ID INT NOT NULL LASTNAME VARCHAR(255) FirstName VARCHAR(255) NOT NULL, CONSTRAINT PK_Student PRIMARY KEY (ID, FirstName));ALTER TABLE Students /* SET a column as primary key */ADD PRIMARY KEY (ID);ALTER TABLE Students /* Set multiple columns as primary key */ADD CONSTRAINT PK_Student /*Naming a Primary Key*/PRIMARY KEY (ID, FirstName); write a sql statement to add primary key 't_id' to the table 'teachers'. Check Write a SQL statement to add primary key constraint 'pk_a' for table 'table_a' and fields 'col_b, col_c'. Check
|