Primary key in sql server example.
Primary key constraints in SQL. Primary key constraint is used to restrict duplicate value in the table.
PRIMARY KEY Constraint Syntax:
CREATE TABLE table_name
(
column_name data_type NULL/NOT NULL CONSTRAINT constraint_name PRIMARY KEY
.............
............
)
PRIMARY KEY Constraint example
CREATE TABLE OrderDetails ( OrderId varchar(10) NOT NULL CONSTRAINT orderprimary PRIMARY KEY, ProductName varchar(20) NOT NULL, OrderQuantity int NOT NULL, ProductPrice float NOT NULL, CustomerPhone varchar(20)NOT NULL )
INSERT INTO OrderDetails VALUES('001','iPhone','100','500','01657684759') INSERT INTO OrderDetails VALUES('002','Laptop','200','700','01657435435') INSERT INTO OrderDetails VALUES('003','Printer','100','300','01655645332')
Description: Apply unique value on OrderId column in above table. OrderId can not be duplicate.
PRIMARY KEY CONSTRAINTS example in video
PRIMARY KEY CONSTRAINTS example in Image
No comments:
Post a Comment