Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
7 views2 pages

Assignment 1

The document outlines SQL commands for creating and modifying database tables for departments (Dept) and employees (Emp). It includes constraints for primary keys, foreign keys, and checks for data integrity, as well as commands for inserting, updating, deleting, and querying data. Additionally, it demonstrates renaming tables and modifying column types and constraints.
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)
7 views2 pages

Assignment 1

The document outlines SQL commands for creating and modifying database tables for departments (Dept) and employees (Emp). It includes constraints for primary keys, foreign keys, and checks for data integrity, as well as commands for inserting, updating, deleting, and querying data. Additionally, it demonstrates renaming tables and modifying column types and constraints.
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/ 2

create table Dept(dept number(2) constraint pk_dept primary key,dname varchar(20)

constraint nn_dname not null, loc varchar(20) constraint nn_loc not null);

create table Emp(empno number(10) constraint pk_empno primary key,ename varchar(20)


constraint nn_ename not null,hiredate date ,mgr number(10) constraint nn_mgr not
null, sal number(7,2) constraint nn_sal not null,comm number(7,2) constraint
nn_comm not null, deptno number(10) constraint fk_deptno references Dept(deptno));

alter table Emp add(Nationality varchar(10),Passport number(10) unique);

alter table Emp modify(Passport varchar(10));

alter table Emp drop(Nationality ,Passport);

alter table Emp modify(comm Constraint ck_comm check(comm>0));

alter table Emp drop constraint ck_comm;

alter table Emp add (Marital_Status char);

alter table Emp add constraint ck_ms check (Marital_Status ='y' and
Marital_status='n');

alter table Emp modify(Marital_status constraint nn_Marital_Status not null);

alter table emp drop constraint nn_marital_status;

alter table emp add constraint nn_marital_status check (Marital_status in('y'/'n')


and marital_status is not null );

rename emp to emplyoee;

rename emplyoee to emp;

alter table emp modify(mgr varchar(15));

alter table emp drop constraint ck_ms;

desc emp;

insert into dept values(10,'cse','Baroda');

update emp set Marital_status='y' where deptno=10;

insert into dept values(20,'Mech','Baroda');

delete from dept where dept=20;

truncate table emp;

drop table emp;


create table Emp(empno number(10) constraint pk_empno primary key,ename varchar(20)
constraint nn_ename not null,hiredate date ,mgr number(10) constraint nn_mgr not
null, sal number(7,2) constraint nn_sal not null,comm number(7,2) constraint
nn_comm not null, deptno number(10) constraint fk_deptno references Dept(dept));

insert into dept values(30,'Civil','Baroda');

insert into dept values(40,'Chemical','Baroda');

select * from dept;

insert into dept values(50,'Pharma','Kpd');

select * from dept order by loc;

select * from dept order by dept;

select * from dept where dept between 10 and 40;

select * from dept where dname like 'C%';

select * from dept where dname not like 'C%';

You might also like