DML Commands: To Create An Employee Table

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

DML COMMANDS

To create an employee table

SQL>create table employee(empno number(4),ename varchar(15),job char(10),dob. date,salary


number(5),comm number(7),deptno number(5));
Table created
SQL>desc employee;
Name Null? Type
------------------- ---------------------- -------------------------------
EMPNO NUMBER(4)
ENAME VARCHAR(15)
JOB CHAR(10)
DOB DATE
SALARY NUMBER(5)
COMM NUMBER(5)
DEPTNO NUMBER(5)

To insert a single record


SQL>insert into employee values(7369,'smith','clerk',17-DEC-80,800,0,20);
1 row created
SQL>select * from employee;
EMPNO ENAME JOB DOB SALARY COMM DEPTNO
7369 smith clerk 17-DEC-80 800 0 20

To insert multiple records

SQL>insert into employee values(&empno,'&ename','&job',&dob,&salary,&comm,&deptno);


Enter value for empno: 7399
Enter value for ename:asant
Enter value for job:salesman
Enter value for dob:20-FEB-81
Enter value for salary:1600
Enter value for comm:300
Enter value for deptno:20

old 1:insert into employee values(&empno,'&ename','&job',&dob,&salary,&comm,&deptno);


new 1:insert into employee values(7399,'asant','salesman',20-FEB-81,1600,300,20);
1 row created
SQL>/
Enter value for empno: 7499
Enter value for ename:allen
Enter value for job:salesman
Enter value for dob:20-FEB-81
Enter value for salary:1600
Enter value for comm:300
Enter value for deptno:30
old 1:insert into employee values(&empno,'&ename','&job',&dob,&salary,&comm,&deptno);
new 1:insert into employee values(7499,'allen','salesman',20-FEB-81,1600,300,30);
1 row created
SQL>/
Enter value for empno: 7521
Enter value for ename:ward
Enter value for job:salesman
Enter value for dob:22-FEB-82
Enter value for salary:1600
Enter value for comm:300
Enter value for deptno:30
old 1:insert into employee values(&empno,'&ename','&job',&dob,&salary,&comm,&deptno);
new 1:insert into employee values(7521,'ward','salesman',22-FEB-82,1600,300,30);
1 row created.......similarly several records are inserted

SELECT COMMANDS

SQL>select *from employee;

EMPNO ENAME JOB DOB SALARY COMM DEPTNO


7369 smith Clerk 17-DEC-80 800 0 20
7399 Asant salesman 20-FEB-81 1600 300 20
7499 Allen salesman 20-FEB-81 1600 300 30
7521 ward salesman 22-FEB-82 1250 500 30
7566 jones manager 22-JAN-82 1250 500 30
7698 Blake Manager 01-MAY-78 9850 1400 30
7611 scott Hod 12-JUN-76 3000 0 10
7368 Ford supervisor 17-DEC-80 800 0 20
7599 alley salesman 20-FEB-81 1600 300 30
7421 drank Clerk 22-JAN-82 1250 500 30
10 row selected

To retrieve specific record from the table ( using where clause)

SQL>select empno,ename,job,dob,salary,comm,deptno from employee where deptno=30;

EMPNO ENAME JOB DOB SALARY COMM DEPTNO


7499 Allen salesman 20-FEB-81 1600 300 30
7521 ward salesman 22-FEB-82 1250 500 30
7698 Blake Manager 01-MAY-78 9850 1400 30
7421 drank Clerk 22-JAN-82 1250 500 30

Elimination of duplicate values from select clause

SQL>select distinct deptno from employee;

Deptno
30
20
10
Update command

SQL>update employee set comm=1000 where empno=7369;


1 row updated
SQL>select * from employee where empno=7369;

EMPNO ENAME JOB DOB SALARY COMM DEPTNO


7369 Smith clerk 17-DEC-80 800 1000 20

Select command with the order by clause


SQL>select empno,ename,job,dob,salary,comm,deptno from employee order by ename;

EMPNO ENAME JOB DOB SALARY COMM DEPTNO


7499 Allen salesman 20-FEB-81 1600 300 30
7399 Asant salesman 20-FEB-81 1600 300 20
7698 Blake Manager 01-MAY-78 9850 1400 30
7421 drank Clerk 22-JAN-82 1250 500 30
7566 jones manager 22-JAN-82 1250 500 30
7611 scott Hod 12-JUN-76 3000 10 10
7369 Smith clerk 17- DEC-80 800 1000 20
7521 ward salesman 22-FEB-82 1250 500 30
8 rows selected

Delete command
SQL>delete from employee where deptno=30;5 rows deleted
SQL>select * from employee;
EMPNO ENAME JOB DOB SALARY COMM DEPTNO
7399 Asant salesman 20-FEB-81 1600 300 20
7611 scott Hod 12-JUN-76 3000 10 10
7369 Smith clerk 17- DEC-80 800 1000 20

You might also like