0% found this document useful (0 votes)
10 views1 page

SQL Best Commands

The document contains SQL statements for creating four tables: BRANCH, PRODUCT, FACULTY, and CUSTOMER. Each table has defined columns with specific data types, constraints for primary keys, unique values, and checks for data integrity. The CUSTOMER table includes a foreign key reference to a STUDENT table, which is not defined in the document.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views1 page

SQL Best Commands

The document contains SQL statements for creating four tables: BRANCH, PRODUCT, FACULTY, and CUSTOMER. Each table has defined columns with specific data types, constraints for primary keys, unique values, and checks for data integrity. The CUSTOMER table includes a foreign key reference to a STUDENT table, which is not defined in the document.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

CREATE TABLE BRANCH

(BID INT UNSIGNED NOT NULL ,


BNAME VARCHAR(20) NOT NULL,
LOCATION VARCHAR(20) NOT NULL,
PINCODE INT UNSIGNED NOT NULL,
CONSTRAINT P_BID PRIMARY KEY(BID),
CONSTRAINT U_PIN UNIQUE(PINCODE),
CONSTRAINT C_PIN CHECK(LENGTH(PINCODE)=6)
);

CREATE TABLE PRODUCT


(PID INT UNSIGNED NOT NULL,
PNAME VARCHAR(10) NOT NULL,
PRICE INT UNSIGNED NOT NULL,
CATEGORY VARCHAR(20) NOT NULL,
QUANTITY INT UNSIGNED NOT NULL,
CONSTRAINT P_PID PRIMARY KEY(PID),
CONSTRAINT C_PRICE CHECK(PRICE>0),
CONSTRAINT C_QUANTITY CHECK(QUANTITY>0)
);

CREATE TABLE FACULTY


(
FID INT UNSIGNED NOT NULL PRIMARY KEY,
FNAME VARCHAR(20) NOT NULL,
SUBJECT VARCHAR(20) NOT NULL,
DNAME VARCHAR(10),
PHONE INT UNSIGNED NOT NULL UNIQUE,CHECK(LENGTH(PHONE)=10)
);

CREATE TABLE CUSTOMER


(
CID INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
CNAME VARCHAR(20) NOT NULL,
AGE INT UNSIGNED NOT NULL ,
ORDER_ID INT UNSIGNED,
CITY VARCHAR(20) NOT NULL,
BALANCE DECIMAL(10,2) UNSIGNED NOT NULL DEFAULT'100',
SID INT UNSIGNED,
CONSTRAINT FOREIGN KEY(SID)REFERENCES STUDENT(SID)
);

You might also like