SYMCA DIV – A
Name - Rohit Chavan Rollno.06
ASSIGNMENT 2
Constraints
Q1. Explain in detail all the constraints along with rules and syntax
• Create Syntax
• Alter Syntax
• Drop Syntax
• Disable Syntax
• Enable Syntax
PRIMARY KEY:
A primary key is a field in a table which uniquely identifies each row/record in a database
table. Primary keys must contain unique values.
Syntax: CREATE TABLE table_name
Column datatype (size) CONSTRAINT constraint_name PRIMARY KEY,
Column datatype (size)
);
• Create Syntax
CREATE TABLE table_name
(
Column datatype (size) CONSTRAINT constraint_name PRIMARY KEY,
Column datatype (size)
);
• Alter Syntax
ALTER TABLE table_name ADD CONSTRAINT
constraint_name_Column_table_name CONSTRAINT;
• Drop Syntax
ALTER TABLE table_name DROP CONSTRAINT
constraint_name_Column_table_name;
SYMCA DIV – A
Name - Rohit Chavan Rollno.06
• Disable Syntax
ALTER TABLE table_name DISABLE CONSTRAINT constraint_name;
• Enable Syntax
ALTER TABLE table_name ENABLE CONSTRAINT constraint_name;
Q2. Create following schema along with their constraints
STUDENT
REG_NO FNAME LNAME BDATE ADDRESS GENDER CITY PINCODE
COURSE
COURSE_NO CNAME DEPT_NAME
ENROLL
REG_NO COURSE_NO SEM MARKS ENROLL_DATE
BOOK_ADOPTATION
COURSE_NO SEM BOOK_ISBN PRICE
TEXT
BOOK_ISBN BOOK_TITLE PUBLISHER PUB_DATE AUTHOR_ID PRICE NO_OF_COPIES
AUTHOR
AUTHOR_ID ANAME CITY STATE PINCODE DOB
SYMCA DIV – A
Name - Rohit Chavan Rollno.06
Student:
• Apply Reg_No as a primary key and must begin with SR.
SYMCA DIV – A
Name - Rohit Chavan Rollno.06
• Check Fname not null
• Check Gender like Male and Female.
SYMCA DIV – A
Name - Rohit Chavan Rollno.06
• Check that address is equal to ‘Mumbai’, ’Nagpur’, ’Kota’ or
‘Pune’.
COURSES
• Apply Course_No as primary key
• Check Dept_Name is Not Null
SYMCA DIV – A
Name - Rohit Chavan Rollno.06
• Check Cname is Not Null
ENROLL
• Apply Course_No as foreign key on existing Course Table
• Apply Reg_No, Course_No and Sem as composite Unique key
SYMCA DIV – A
Name - Rohit Chavan Rollno.06
• Set the default value for Marks as 0
• Remove the default value set on Marks
AUTHORS
• Apply Author_id as primary key and must begin with AU or A.
• City should not be null
SYMCA DIV – A
Name - Rohit Chavan Rollno.06
TEXT
• Apply Book_ISBN as primary key
• Apply Author_ID as foreign key referencing Author Table
• Check No_Of_Copies should not be 0 or Null
• Disable constraint on No_Of_Copies column
TABLE_ADOPTATION
• Apply Course_No as foreign key on Course Table.
SYMCA DIV – A
Name - Rohit Chavan Rollno.06
• Apply Book_ISBN as foreign key on Text Table
• Check price is greater than 50 and Not Null