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

EMP & DEPT tables with SQL

The document provides SQL commands for creating two tables: DEPT and EMP, along with their respective data structures and constraints. It also includes SQL commands for inserting sample data into both tables. After executing the SQL commands, the resulting DEPT and EMP tables are displayed with their contents.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

EMP & DEPT tables with SQL

The document provides SQL commands for creating two tables: DEPT and EMP, along with their respective data structures and constraints. It also includes SQL commands for inserting sample data into both tables. After executing the SQL commands, the resulting DEPT and EMP tables are displayed with their contents.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

SQL for creating DEPT Table

create table dept(


deptno number(2,0),
dname varchar2(14),
loc varchar2(13),
constraint pk_dept primary key (deptno) );

SQL for creating EMP Table


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),
constraint pk_emp primary key (empno),
constraint fk_deptno foreign key (deptno) references dept (deptno) );

SQL for inserting data into Dept Table


insert into dept values(10, 'ACCOUNTING', 'NEW YORK');
insert into dept values(20, 'RESEARCH', 'DALLAS');
insert into dept values(30, 'SALES', 'CHICAGO');
insert into dept values(40, 'OPERATIONS', 'BOSTON');

SQL for inserting data into Emp Table


insert into emp values
( 7839, 'KING', 'PRESIDENT', null, '17-NOV-1981', 5000, null, 10 );
insert into emp values
( 7698, 'BLAKE', 'MANAGER', 7839, '1-MAY-1981', 2850, null, 30 );
insert into emp values
( 7782, 'CLARK', 'MANAGER', 7839, '9-JUN-1981', 2450, null, 10 );
insert into emp values
( 7566, 'JONES', 'MANAGER', 7839, '2-APR-1981', 2975, null, 20 );
insert into emp values
( 7788, 'SCOTT', 'ANALYST', 7566, '13-JUL-87', 3000, null, 20 );
insert into emp values
( 7902, 'FORD', 'ANALYST', 7566, '3-DEC-1981', 3000, null, 20 );
insert into emp values
( 7369, 'SMITH', 'CLERK', 7902, '17-DEC-1980', 800, null, 20 );
insert into emp values
( 7499, 'ALLEN', 'SALESMAN', 7698, '20-FEB-1981', 1600, 300, 30 );
insert into emp values
( 7521, 'WARD', 'SALESMAN', 7698, '22-FEB-1981', 1250, 500, 30 );
insert into emp values
( 7654, 'MARTIN', 'SALESMAN', 7698, '28-SEP-1981', 1250, 1400, 30 );
insert into emp values
( 7844, 'TURNER', 'SALESMAN', 7698, '8-SEP-1981', 1500, 0, 30 );
insert into emp values
( 7876, 'ADAMS', 'CLERK', 7788, '13-JUL-87', 1100, null, 20 );
insert into emp values
( 7900, 'JAMES', 'CLERK', 7698, '3-DEC-1981', 950, null, 30 );
insert into emp values
( 7934, 'MILLER', 'CLERK', 7782, '23-JAN-1982', 1300, null, 10 );
After you run the above SQLs, you will get the following tables

DEPT table
DEPTNO DNAME LOC
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy