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

DML Commands: To Create An Employee Table

1. The document describes various DML commands in SQL like CREATE, INSERT, SELECT, UPDATE, DELETE. 2. It shows how to create a table, insert single and multiple records, retrieve records using WHERE clause, eliminate duplicates, update records, order results, and delete records. 3. Examples are provided for each command to demonstrate their proper usage.

Uploaded by

vasan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
119 views

DML Commands: To Create An Employee Table

1. The document describes various DML commands in SQL like CREATE, INSERT, SELECT, UPDATE, DELETE. 2. It shows how to create a table, insert single and multiple records, retrieve records using WHERE clause, eliminate duplicates, update records, order results, and delete records. 3. Examples are provided for each command to demonstrate their proper usage.

Uploaded by

vasan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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