0% found this document useful (0 votes)
2 views8 pages

SQLMANUAL

The document outlines the creation and manipulation of four SQL tables: DEP, EMP, CUST, and SALGRADE, including their structures and sample data inserts. It provides SQL commands for inserting, updating, selecting, and deleting records in these tables. Additionally, it includes queries to retrieve specific employee information and department details.

Uploaded by

ahanasayeed.786
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)
2 views8 pages

SQLMANUAL

The document outlines the creation and manipulation of four SQL tables: DEP, EMP, CUST, and SALGRADE, including their structures and sample data inserts. It provides SQL commands for inserting, updating, selecting, and deleting records in these tables. Additionally, it includes queries to retrieve specific employee information and department details.

Uploaded by

ahanasayeed.786
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/ 8

1)Create DEP(Department) table

CREATE TABLE DEP (

DEP_ID INT PRIMARY KEY,

DNAME CHAR(10),

DMGR_ID INT

);

Table Created

COMMANDS To see the structure of a DEP table:

DESC DEP;

To Insert The values In DEP Table


SQL> INSERT INTO DEP VALUES (1, 'RESEARCH', 1003);
1 row created.

SQL> INSERT INTO DEP VALUES (2, 'ADMIN', 1002);


1 row created.

SQL> INSERT INTO DEP VALUES (3, 'PRODUCTION', 1004);


1 row created.

SQL> INSERT INTO DEP VALUES (4, 'SALES', 1005);


1 row created.

SQL> INSERT INTO DEP VALUES (5, 'HR', 1001);


1 row created.

To save the SQL COMMANDS


SQL> COMMIT;
Commit complete.
SQL Command To see the values that you inserted into a DEP table

select * from DEP;

2) Create EMP(Employee) table


CREATE TABLE EMP (
EMP_ID INT PRIMARY KEY,
FNAME CHAR(10),
LNAME CHAR(10),
JOB_ID CHAR(10),
DOJ DATE,
SAL NUMBER(10, 5),
MGR_ID INT REFERENCES EMP(EMP_ID),
DEP_ID INT REFERENCES DEP(DEP_ID)
);

Table created.

COMMAND To see the structure of a EMP table:

DESC EMP;
To Insert The values In EMP Table
SQL>INSERT INTO EMP VALUES (1001,'ANIL','CHOWDARY','MANAGER','01-JAN-2000', 25000, 1001, 2);
1 row created.

SQL> INSERT INTO EMP VALUES (1002,'SANDEEP','SHARMA','ANALYST','01-FEB-2000', 23000, 1001, 3);


1 row created.

SQL> INSERT INTO EMP VALUES (1003,'BHARATH','SINGHVI','TRAINEE','01-MAR-2000', 22000, 1001, 5);


1 row created.

SQL> INSERT INTO EMP VALUES (1004,'SUSHEEL','SHARMA','CLERK','01-APR-2000', 21000, 1001, 1);


1 row created.

SQL> INSERT INTO EMP VALUES (1005,'SACHIN','VERMA','ANALYST','01-MAY-2000', 20000, 1001, 4);


1 row created.

To save the SQL COMMANDS


SQL> COMMIT;
Commit complete.

SQL Command To see the values that you inserted into a EMP table

select * from EMP;


1)Working with Table and data using another Table
Query 1: Select employee with EMP_ID = 1003
SQL> SELECT * FROM EMP WHERE EMP_ID=1003;

Query 2: Show all the employees who are in department number 3.


SQL> SELECT * FROM EMP WHERE DEP_ID=3;

Query 3: Write an SQL query to update the salary to 18,000 for the employee whose
EMP_ID is 1004.
SQL> UPDATE EMP SET SAL = 18000 WHERE EMP_ID = 1004;

To see the updated table after making changes (like updating a salary), use the
SELECT statement.
SQL>select * from EMP;
Query 4: Write an SQL query to display the employee id (EMP_ID) and salary (SAL) of
the employee whose EMP_ID is 1004.

SQL> SELECT EMP_ID, SAL FROM EMP WHERE EMP_ID = 1004;

Query 5: Write an SQL query to display the Employee ID, First Name, Last Name, and
Department Name of employees who are department managers.

SQL> SELECT EMP_ID, FNAME, LNAME, DNAME FROM EMP, DEP WHERE EMP_ID=DMGR_ID;

Query 6:Write an SQL query to Delete the record whose EMP_ID is 1003

SQL> DELETE FROM EMP WHERE EMP_ID=1003;


3)Create CUST(Customer) table

CREATE TABLE CUST (


CUST_ID INT PRIMARY KEY,
FNAME CHAR(10),
LNAME CHAR(10),
ADDR VARCHAR2(20),
CITY CHAR(10),
PHONE INT,
EMAIL VARCHAR2(20)
);

Table created.
COMMAND To see the structure of a CUST table:

DESC CUST;

To Insert The values In CUST Table


SQL> INSERT INTO CUST VALUES (101,'ANAND','A','JAYANAGARA','DAVANAGERE',1234567890,'[email protected]');
1 row created.

SQL> INSERT INTO CUST VALUES (102,'ARAVIND','V','J P NAGAR','BENGALURU',2345678901,'[email protected]');


1 row created.

SQL> INSERT INTO CUST VALUES(103,'GANESH','G','J C EXTN','MYSORE',3456789012,'[email protected]');


1 row created.

SQL> INSERT INTO CUST VALUES (104,'SURESH','S','VIDYA NAGAR','TUMKUR', 467890123,'[email protected]');


1 row created.

SQL> INSERT INTO CUST VALUES(105,'KISHOR','K','RAJAJI NAGAR','SHIMOGA',5678901234,'[email protected]');


1 row created.
To save the SQL COMMAND
SQL> COMMIT;
Commit complete.
SQL Command To see the values that you inserted into a CUST table

select * from CUST;

4) Create SALGRADE table

CREATE TABLE SALGRADE (


GRADE CHAR(10),
HIGH_SAL NUMBER(10, 5),
LOW_SAL NUMBER(10, 5)
);

Table created.

COMMAND To see the structure of a SALGRADE table:

DESC SALGRADE;
To Insert The values In SALGRADE Table

SQL> INSERT INTO SALGRADE VALUES ('GRADE-1', 50000, 25000);


1 row created.

SQL> INSERT INTO SALGRADE VALUES ('GRADE-2', 40000, 20000);


1 row created.

SQL> INSERT INTO SALGRADE VALUES ('GRADE-3', 30000, 15000);


1 row created.

SQL> INSERT INTO SALGRADE VALUES ('GRADE-4', 25000, 12500);


1 row created.

SQL> INSERT INTO SALGRADE VALUES ('GRADE-5', 20000, 10000);


1 row created.

To save the SQL COMMAND


SQL> COMMIT;
Commit complete.

SQL Command To see the values that you inserted into a SALGRADE table

select * from SALGRADE;

You might also like