DBMS
DBMS
ASSIGNMENT-1
1. Create a table inSQL.Table name is Departments and attributes are deptno, name,
location
CREATE TABLE DEPARTMENTS(DEPTNO NUMBER,
NAME VARCHAR2(20),
LOCATION VARCHAR(30));
2. Write a SQL statement to display the schema of Departments table.
DESC DEPARTMENTS;
3. Write a SQL statement to insert these rows into Departments Table.
INSERT INTO DEPARTMENTS VALUES(1,'CSE','KANKINARA');
INSERT INTO DEPARTMENTS VALUES(2,'ECE,'JAGADDAL');
INSERT INTO DEPARTMENTS VALUES(3,'CST,'KOLKATA');
4. Write a SQL statement to display all the records in the Departments Table.
SELECT * FROM DEPARTMENTS;
5. Write a SQL statement to display only deptno from Departments.
SELECT DISTINCT DEPTNO FROM DEPARTMENTS;
6. Write a SQL statement to display only deptno from Departments table.
SELECT NAME,LOCATION FROM DEPARTMENTS;
7. Write a SQL statement to add new column ‘no_of_emp’ in existing Departments table.
ALTER TABLE DEPARTMENTS ADD NO_OF_EMP NUMBER;
8. Write a SQL statement to update Departments table to add value in
mo_of_emp=11,column where deptno=1
UPDATE DEPARTMENTS SET NO_OF_EMP=11 WHERE DEPTNO=1;
9. Write a SQL statement to display Departments table.
SELECT * FROM DEPARTMENTS;
ASSIGNMENT-2
1. Create a empl208 table with column (eid,ename,eaddress,esal).
CREATE TABLE EMPL208( EID NUMBER(3),
ENAME VARCHAR(30),
EADDRESS VARCHAR(50),
ESAL NUMBER(10));
2. Insert values.
INSERT INTO EMPL208 VALUES(209,'A K GHOSH','MUMBAI',30000);
INSERT INTO EMPL208 VALUES(249,'B DAS','KOLKATA',50000);
INSERT INTO EMPL208 VALUES(219,'P SHAW','KOLKATA',30000);
INSERT INTO EMPL208 VALUES(239,'P DAS','KALYANI',10000);
INSERT INTO EMPL208 VALUES(229,'G DEBNATH','KALYANI',50000);
INSERT INTO EMPL208 VALUES(259,'a DAS','KOLKATA',10001);
3. Select the name of the employee whose salary is 10001 and address in Kolkata.
SELECT ENAME FROM EMPL208 WHERE ESAL=10001 AND
EADDRESS='KOLKATA';
4. Select the name of the employee whose salary is greater than 10000 and address
in Kolkata.
SELECT ENAME FROM EMPL208 WHERE ESAL>10000 AND
EADDRESS='KOLKATA';
5. Select the name of the employee whose salary is greater than 10000.
SELECT ENAME FROM EMPL208 WHERE ESAL>10000;
7. . Find the address and name of the employee whose salary is greater than 30000.
SELECT ENAME FROM EMPL208 WHERE ESAL>30000;
8. Find the employee id and salary whose belongs to Mumbai.
SELECT EID,ESAL FROM EMPL208 WHERE EADDRESS='MUMBAI';
11. Find the employee id and name salary is greater than 30000 and less than 50000.
SELECT EID,ENAME FROM EMPL208 WHERE 30000<ESAL AND ESAL<50000;
3. Find the first name and last name of the student whose subject is maths or physics.
SELECT FNAME,LNAME FROM STUDENT2008 WHERE SUBJECT='MATH' OR
SUBJECT='PHYSICS';
4. Find the first name last name and age of the student whose age is between 10 to 15.
SELECT FNAME,LNAME,AGE FROM STUDENT2008 WHERE AGE>10 AND AGE<15;
5. Find first name,lastname and game of the student whose game is not football.
SELECT FNAME,LNAME,GAME FROM STUDENT2008 WHERE GAME='FOOTBALL';
6. Find the first name,last name and game of the student whose age is between 10 to 15 or
game is not football.
SELECT FNAME,LNAME,GAME FROM STUDENT2008 WHERE AGE>10 AND AGE<15;
7. Find the first name and the last name of the student whose first name starts with r.
SELECT FNAME,LNAME FROM STUDENT2008 WHERE FNAME LIKE 'R%';
8. Find the first name and the last name of the student whose first name's second letter is
-n.
SELECT FNAME,LNAME FROM STUDENT2008 WHERE FNAME LIKE '_N%';
9. Find the first name,last name and age of the student whose age is between 10 to 15
using BETWEEN and AND keywords.
SELECT FNAME,LNAME,AGE FROM STUDENT2008 WHERE AGE BETWEEN 10 AND 15;
10. Find first name,last name of the student whose subject is maths or cs using IN
keywords.
SELECT FNAME,LNAME FROM STUDENT2008 WHERE SUBJECT IN('MATH','CS');
11. Find the first name, last name of the student whose game is null.
SELECT FNAME,LNAME FROM STUDENT2008 WHERE GAME='NULL';
12. Find first, last name and subject of the student whose subject is neither maths nor
physics using NOT IN keywords.
SELECT FNAME,LNAME FROM STUDENT2008 WHERE SUBJECT NOT
IN('MATH','PHYSICS');