Primary Key
The PRIMARY KEY Constraint used to uniquely identifies each record in a table.
Primary Key must contain UNIQUE value. It cannot contain NULL values and the rest of the table data must be unique and each table can have Only ONE primary key.
PRIMARY KEY it is also given on Column level (Single column) and also on table column (Multiple column).
Syntax : For Column Level
CREATE TABLE table_name
(
column_name datatype PRIMARY_KEY,
column_name datatype,
- - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - -
);
Example : Let's see How to create PRIMARY KEY in table. we create a table , the id on this table is set PRIMARY KEY for this column.
Query :
Output :
CREATE TABLE my_tab
(
Id int(10) NOT NULL PRIMARY KEY,
Name varchar(30),
Address varchar(50)
);
Primary key in Table is created, Now you can use DESC command and see the table.
Query :
DESC my_tab;
Output :
0 Comments