Exp 2
Exp 2
Exp 2
ROLL NO: 14
YEAR: 1st
SEMESTER: 2nd
mysql> create table department (deptno int (3), dname varchar (20) unique,
location varchar (20) not null check (location in ('Delhi', 'Agra',' Pune')),
primary key(deptno));
mysql> create table employee (empno varchar (5) check (empno like 'e%')
primary key, ename varchar (20) unique, designation varchar (20) not null,
salary int (10) check (salary between 15000 and 50000) default 25000, dob
date not null, dno int (3), foreign key(dno) references department (deptno));
4.Make sID in Apply foreign key referring table student and cName
referring table college.
mysql> alter table apply add foreign key(SID) references student(SID), add
foreign key (cName) references college(cName);
5.Increase data type size of major from 20 to 25.
mysql> alter table apply modify major varchar(25);
8. Drop foreign key on column name cName from Apply table. mysql>
alter table apply drop foreign key apply_ibfk_2;
9. Remove column sizeHS from Student table.
mysql> alter table student drop column sizeHS;
10. Drop primary key from college. mysql> alter table college drop
primary key;
11. Make cname, major unique pairwise such as Stanford CS, Stanford EE.
mysql> alter table apply add constraint unique_pair_apply unique
(cName, major);
12. Add cName as Foreign Key in Apply table referring table College using
on delete cascade.
mysql> alter table college add primary key(cName); mysql>
alter table apply add Foreign key(cName) references
college(cName) on delete cascade;
13. Modify foreign key on sID in Apply table to foreign key on delete set
null.
mysql> alter table apply drop foreign key apply_ibfk_1;
mysql> alter table apply add foreign key(sID) references student(sid) on
delete set null;