Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Assignment 1

Data Definition Language Create and Alter Statements

1 create table employee (empid varchar2(10), ename


varchar2 (10), doj date)
a. create table employee (empid varchar2(10), ename
varchar2(10), doj date);

2 rename this table to emp followed by ur roll number


a. rename employee to emp123;

3 alter table add salary number (5) and address


varchar2(15)
a. alter table emp123 add (salary number (5), address
varchar2 (15))
4 increase the size of ad address to 30
a. alter table emp123 modify address varchar2 (30);

5 make salary column not null


a. alter table emp123 modify salary not null;
6 delete address column
a. alter table emp123 drop column address;
7 rename doj to date of joining
a. alter table emp123 rename column doj to
date_of_joining;
8 make empid as primary key
a. alter table emp123 add primary key (empid);
9 add dob
a. alter table emp123 add dob date;
10 dob should be less than doj
a. alter table emp123 add constraint dobdoj
check(dob<date_of_joining);
11 change datatype of empid
a. alter table emp123 modify empid number(10);
12 create a table department with dno as primary key and
dname & dloc as varchar2 type (10)
a. create table department (dno number(10) primary key,
dname varchar2(10));
13 make dno as foreign key in emp table
a. alter table emp123 add foreign key (dno) references
department(dno);
For this we need to add a column of dno in employee table
first.
 alter table emp123 add dno number(10);

For entering values we move to DML

Entering values in department table:


insert into department values(1,'Research','Delhi');

insert into emp123 values(1,'Ayush','1-nov-22',1000,'13-apr-


94',1);

Inserting values in table using &%


 insert into per values (&pid, & pname, &sal,
&address, &dno)

You might also like