0% found this document useful (0 votes)
99 views

Oracle Tables

The document contains the DDL statements to create tables DEPT and EMP, with sample data. It also creates primary keys and foreign keys. Additional tables COMP_DTLS, PROD_DTLS, CUST_DTLS, ACT_TYPES and CUST_ACT_DTLS are created along with the relationships between them. Finally, sequences, indexes are created for the student and course tables.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views

Oracle Tables

The document contains the DDL statements to create tables DEPT and EMP, with sample data. It also creates primary keys and foreign keys. Additional tables COMP_DTLS, PROD_DTLS, CUST_DTLS, ACT_TYPES and CUST_ACT_DTLS are created along with the relationships between them. Finally, sequences, indexes are created for the student and course tables.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

--------------------------------------------------------

-- File created - Sunday-April-27-2014


--------------------------------------------------------
--------------------------------------------------------
-- DDL for Table DEPT
--------------------------------------------------------

CREATE TABLE "DEPT" ("DEPTNO" NUMBER(2,0), "DNAME" VARCHAR2(14), "LOC"


VARCHAR2(13));

Insert into DEPT (DEPTNO,DNAME,LOC) values (10,'ACCOUNTING','NEW YORK');


Insert into DEPT (DEPTNO,DNAME,LOC) values (20,'RESEARCH','DALLAS');
Insert into DEPT (DEPTNO,DNAME,LOC) values (30,'SALES','CHICAGO');
Insert into DEPT (DEPTNO,DNAME,LOC) values (40,'OPERATIONS','BOSTON');
--------------------------------------------------------
-- DDL for Index PK_DEPT
--------------------------------------------------------

CREATE UNIQUE INDEX "PK_DEPT" ON "DEPT" ("DEPTNO");

--------------------------------------------------------
-- Constraints for Table DEPT
--------------------------------------------------------

ALTER TABLE "DEPT" ADD CONSTRAINT "PK_DEPT" PRIMARY KEY ("DEPTNO") ENABLE;

--------------------------------------------------------
-- File created - Sunday-April-27-2014
--------------------------------------------------------
--------------------------------------------------------
-- DDL for Table EMP
--------------------------------------------------------

CREATE TABLE "EMP" ("EMPNO" NUMBER(4,0), "ENAME" VARCHAR2(10), "JOB" VARCHAR2(9),


"MGR" NUMBER(4,0), "HIREDATE" DATE, "SAL" NUMBER(7,2), "COMM" NUMBER(7,2), "DEPTNO"
NUMBER(2,0));

Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values


(7369,'SMITH','CLERK',7902,to_date('17-DEC-80','DD-MON-RR'),800,null,20);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values
(7499,'ALLEN','SALESMAN',7698,to_date('20-FEB-81','DD-MON-RR'),1600,300,30);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values
(7521,'WARD','SALESMAN',7698,to_date('22-FEB-81','DD-MON-RR'),1250,500,30);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values
(7566,'JONES','MANAGER',7839,to_date('02-APR-81','DD-MON-RR'),2975,null,20);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values
(7654,'MARTIN','SALESMAN',7698,to_date('28-SEP-81','DD-MON-RR'),1250,1400,30);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values
(7698,'BLAKE','MANAGER',7839,to_date('01-MAY-81','DD-MON-RR'),2850,null,30);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values
(7782,'CLARK','MANAGER',7839,to_date('09-JUN-81','DD-MON-RR'),2450,null,10);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values
(7788,'SCOTT','ANALYST',7566,to_date('19-APR-87','DD-MON-RR'),3000,null,20);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values
(7839,'KING','PRESIDENT',null,to_date('17-NOV-81','DD-MON-RR'),5000,null,10);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values
(7844,'TURNER','SALESMAN',7698,to_date('08-SEP-81','DD-MON-RR'),1500,0,30);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values
(7876,'ADAMS','CLERK',7788,to_date('23-MAY-87','DD-MON-RR'),1100,null,20);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values
(7900,'JAMES','CLERK',7698,to_date('03-DEC-81','DD-MON-RR'),950,null,30);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values
(7902,'FORD','ANALYST',7566,to_date('03-DEC-81','DD-MON-RR'),3000,null,20);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values
(7934,'MILLER','CLERK',7782,to_date('23-JAN-82','DD-MON-RR'),1300,null,10);
--------------------------------------------------------
-- DDL for Index PK_EMP
--------------------------------------------------------

CREATE UNIQUE INDEX "PK_EMP" ON "EMP" ("EMPNO");

--------------------------------------------------------
-- Constraints for Table EMP
--------------------------------------------------------

ALTER TABLE "EMP" ADD CONSTRAINT "PK_EMP" PRIMARY KEY ("EMPNO") ENABLE;

--------------------------------------------------------
-- Ref Constraints for Table EMP
--------------------------------------------------------

ALTER TABLE "EMP" ADD CONSTRAINT "FK_DEPTNO" FOREIGN KEY ("DEPTNO") REFERENCES
"DEPT" ("DEPTNO") ENABLE;

--------------------------------------------------------

-----------------------------------------------------------------------------------
-----

Create Table comp_dtls


(
comp_code varchar2(10)
constraint PK_COMP_CODE PRIMARY KEY,
comp_name varchar2(20),
city varchar2(10)
);

Insert into comp_dtls values('I101','IBM','NEW YORK');


Insert into comp_dtls values('W202','WIPRO','CHICAGO');
Insert into comp_dtls values('D303','DELL','TEXAS');
Insert into comp_dtls values('S404','SAMSUNG','KOREA');

Create table Prod_dtls


(
prod_code varchar2(10),
prod_name varchar2(20),
cost number(7,2),
mfg date,
warrenty varchar2(10)
);

Insert into Prod_dtls values('ILTPQS','LAPTOP',45000,'11-FEB-12','4 YEARS');


Insert into Prod_dtls values('ILTPXS','LAPTOP',34000,'21-MAR-12','4 YEARS');
Insert into Prod_dtls values('ILTPZS','LAPTOP',40000,'12-FEB-13','7 YEARS');
Insert into Prod_dtls values('WDTPG','DESKTOP',23000,'30-OCT-12','1 YEAR');
Insert into Prod_dtls values('WCFLL','LIGHTS',3400,'22-JAN-13','2 YEARS');
Insert into Prod_dtls values('DDTPW','DESKTOP',27000,'13-NOV-12','5 YEARS');
Insert into Prod_dtls values('DLTPG','LAPTOP',46000,'08-JAN-13','2 YEARS');
Insert into Prod_dtls values('DMBLY','MOBILE',32000,'10-JAN-13',NULL);
Insert into Prod_dtls values('SLTPC','LAPTOP',34000,'04-DEC-12','6 MONTHS');
Insert into Prod_dtls values('SLTPD','LAPTOP',45000,'09-DEC-12','2 YEARS');
Insert into Prod_dtls values('SMBLGLXY','MOBILE',24000,'10-JAN-12','1 YEAR');
Insert into Prod_dtls values('SMBLGLXG','MOBILE',21500,'02-FEB-13','1 YEAR');

ALTER TABLE PROD_DTLS


ADD COMP_CODE VARCHAR2(10);

ALTER TABLE PROD_DTLS


ADD CONSTRAINT FK_COMP_CODE FOREIGN KEY(COMP_CODE)
REFERENCES COMP_DTLS(COMP_CODE)
--ON DELETE CASCADE;

UPDATE PROD_DTLS
SET COMP_CODE='I101'
WHERE PROD_CODE LIKE'I%';

UPDATE PROD_DTLS
SET COMP_CODE='W202'
WHERE PROD_CODE LIKE'W%';

UPDATE PROD_DTLS
SET COMP_CODE='D303'
WHERE PROD_CODE LIKE'D%';

UPDATE PROD_DTLS
SET COMP_CODE='S404'
WHERE PROD_CODE LIKE'S%';

DROP TABLE CUST_DTLS ;

Create Table Cust_dtls


(
cno number(5) CONSTRAINT PK_Cno PRIMARY KEY,
cname varchar2(12),
city varchar2(10),
gender char
);

insert into cust_dtls values('11110','Ajay','Texas','M');


insert into cust_dtls values('11111','Kiran','Chicago','M');
insert into cust_dtls values('11112','vinod','Delhi','M');
insert into cust_dtls values('11113','Madhu','Delhi','M');
insert into cust_dtls values('11114','Rocky','Texas','M');
insert into cust_dtls values('11115','Ching Fu','Chicago','F');
insert into cust_dtls values('11116','Sonali','Delhi','F');
insert into cust_dtls values('11117','Sagar','Delhi','M');
insert into cust_dtls values('11118','Sarayu','Texas','F');
insert into cust_dtls values('11119','Pratiksha','Delhi','F');
DROP TABLE ACT_TYPES;

Create table Act_types


(
Act_type varchar2(5) CONSTRAINT PK_ACT_TYPE PRIMARY KEY,
Act_name varchar2(30)
);

Insert into Act_types values('SB','Savings Bank A/c.');


Insert into Act_types values('CA','Current A/c.');
Insert into Act_types values('SAL','Salary A/c.');
Insert into Act_types values('DEMAT','Trading A/c.');
Insert into Act_types values('LOAN','Home loan A/c.');
Insert into Act_types values('FD','Fixed Deposit A/c.');

DROP TABLE CUST_ACT_DTLS;

Create Table Cust_act_dtls


(
actno char(11) constraint pk_actno primary key,
act_type varchar2(5),
constraint fk_act_type FOREIGN key(act_type)
references act_types(act_type)
on delete cascade,
act_open_date date constraint nn_OpenDate Not Null,
act_bal number(8,2),
cno number(5) ,
constraint fk_cno_cad FOREIGN key(cno)
references cust_dtls(cno)
on delete cascade
);

Insert into cust_act_dtls Values


('20035201470','SB','11-MAY-10',49000,'11112');

Insert into cust_act_dtls Values


('20035201471','SAL','21-MAY-11',32000,'11110');

Insert into cust_act_dtls Values


('20035201472','DEMAT','21-MAY-11',123000,'11112');

Insert into cust_act_dtls Values


('20035201473','SB','01-MAR-12',23000,'11111');

Insert into cust_act_dtls Values


('20035201474','SAL','16-OCT-11',11000,'11113');

Insert into cust_act_dtls Values


('20035201475','SB','21-MAY-11',13000,'11114');

Insert into cust_act_dtls Values


('20035201476','SAL','21-MAY-11',23000,'11115');

--Ex: delete table students if already existed


drop table STUDENTS;

----creating sequence for student roll number?


create sequence studrno
start with 1010;

clear buffer;

--creating student table

create table students


(
studid number(5) DEFAULT studrno.nextval,
name varchar2(14) ,
mobno number(10),
mailid varchar2(20)
);

--inserting records
insert into students(name,mobno,mailid)
values('janaki',9898980000,'[email protected]');
insert into students(name,mobno,mailid)
values('vasavi',9898980011,'[email protected]');
insert into students(name,mobno,mailid)
values('suji',9898980012,'[email protected]');
insert into students(name,mobno,mailid)
values('prasad',9898880000,'[email protected]');
insert into students(name,mobno,mailid)
values('raj',8898980000,'[email protected]');
insert into students(name,mobno,mailid)
values('jagan',7898980000,'[email protected]');
insert into students(name,mobno,mailid)
values('kumar',9888980000,'[email protected]');

--delete "courses" table if already existed


drop table courses;

--creating courses table


create table courses
(
ccode varchar2(10) constraint pk_ccode_courses primary key,
name varchar2(23),
fee number(5),
duration varchar2(14)
);

--inserting records into courses

insert into courses values


('ORCL','ORACLE DB DEVELOPER',5000,'60 DAYS');
insert into courses values
('JAVA','JAVA DEVELOPER',1000,'90 DAYS');
insert into courses values
('PYTHON','PYTHON PROGRAMMIN',1400,'60 DAYS');
insert into courses values
('UNX','UNIX / LINUX ',2000,'21 DAYS');
insert into courses values
('C','C PROGRAMMING ',1000,'40 DAYS');
insert into courses values
('C++','C++ PROGRAMMING',2000,'45 DAYS');
--delete trainers table if existed
drop table trainers;

--create trainers table


create table trainers
(
tcode varchar2(10),
tname varchar2(14),
);

--insert records into trainers


insert into trainers values
('t1','dinesh');
insert into trainers values
('t2','nagoor babu');
insert into trainers values
('t3','durga');
insert into trainers values
('t4','swamy naidu');
insert into trainers values
('t5','mohan');

-----------------------------------------------------------------------------------
-----
---------Tables For Set
Operators-------------------------------------------------------
-----------------------------------------------------------------------------------
-----

CREATE TABLE CUST_BR1


(
CID char(5) ,
Cname varchar2(20),
city varchar2(20),
Gender varchar2(7),
Mobile number(10)
);

--------------DATA--------------------------

insert into cust_br1 values('c001','jaya','hyd','male',986612121);


insert into cust_br1 values('c002','kiran','hyd','male',9866986612);
insert into cust_br1 values('c003','hemanth','hyd','male',8888888888);
insert into cust_br1 values('c004','izaq','hyd','female',7676767676);
insert into cust_br1 values
('c005','vasavi','hyd','female',null);
CREATE TABLE CUST_BR2
(
CID char(5),
Cname varchar2(20),
city varchar2(20),
Gender varchar2(7),
Mobile number(10)
);

----------------------DATA-------------------

insert into cust_br2 values


('c001','jabbar','delhi','male',null);
insert into cust_br2 values('c002','hari','delhi','male',9898989898);
insert into cust_br2 values('c003','smith','bangalore','female',8787878787);
insert into cust_br2 values('c004','izaq','hyd','female',7676767676);

CREATE TABLE CUST_BR3


(
CID char(5),
Cname varchar2(20),
city varchar2(20),
Gender varchar2(7),
Mobile number(10)
);

---------------------------DATA--------------------

insert into cust_br3 values


('c001','venkat','chennai','male',2323232323);
insert into cust_br3 values
('c002','kanth','delhi','male',null);
insert into cust_br3 values
('c003','smith','bangalore','female',8787878787);
insert into cust_br3 values
('c004','john','delhi','male',9090909090);
insert into cust_br3 values
('c005','bobby','chennai','female',null);

-----------------------------------------------------------------------------------
-----

You might also like