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

1.

Make your own student table with certainnecessary facts, like your id,name and
branch.
ans: SQL> CREATE TABLE Krishnendu(id number, name varchar2(20), branch
varchar2(10));

Table created.

2. Fill up the table with the records of at least 5 your friends.


ans: SQL> INSERT INTO KRISHNENDU VALUES(&ID, '&NAME', '&BRANCH');

SQL> select * from krishnendu;

ID NAME BRANCH
------- ---------------------- ----------
1 Krish CSE
2 Bibek IT
3 Heena EEE
4 Reena ECE
5 Teena ME

3. It sounds goodif you say "Roll" instead of "ID". So, change it.
ans: SQL> alter table krishnendu rename column id to roll;

Table altered.

SQL> select * from krishnendu;

ROLL NAME BRANCH


------- ----------------- -------------
1 Krish CSE
2 Bibek IT
3 Heena EEE
4 Reena ECE
5 Teena ME

4. Here, I think age & address should also be added. So, append it with default
address oof students as TINT.
ans: SQL> alter table krrishnendu add( address varchar2(30) default 'TINT', age
number);

Table altered.

SQL> select * from krishnendu;

ROLL NAME BRANCH ADDRESS AGE


--------- -------------------- ---------- --------- ----
1 Krish CSE TINT
2 Bibek IT TINT
3 Heena EEE TINT
4 Reena ECE TINT
5 Teena ME TINT

5.Fill up the records with individual student's age.


ans: SQL> update krishnendu set age=23 where roll>=1;
5 rows updated.
SQL> select * from krishnendu;

ROLL NAME BRANCH ADDRESS AGE


--------- -------------------- ---------- --------- ----
1 Krish CSE TINT 23
2 Bibek IT TINT 23
3 Heena EEE TINT 23
4 Reena ECE TINT 23
5 Teena ME TINT 23

6. How do I identify each student uniquely? So make roll number as your primary
key.
ans: SQL> alter table krishnendu modify roll primary key;
Table altered.

NAME Null? TYPE


-------------- ---------- ----------
ROLL NOT NULL NUMBER
NAME VARCHAR2(20)
BRANCH VARCHAR2(20)
AGE NUMBER
ADDRESS VARCHAR2(20)

7.Don't keep the name feild blank for any record.


ans: Table does not have any empty field.

8. Add marks column in the table and add values.


ans: SQL> alter table krishnendu add marks number;
Table altered.

SQL> select * from krishnendu;

ROLL NAME BRANCH ADDRESS AGE MARKS


--------- -------------------- ---------- --------- ---- ---------
1 Krish CSE TINT 23
2 Bibek IT TINT 23
3 Heena EEE TINT 23
4 Reena ECE TINT 23
5 Teena ME TINT 23

5 rows selected.

9.Identify the students who have passed the exam. Cut off marks is 50%.
ans: SQL> update krishnendu set marks=95 where roll>=1;
5 rows updated.

SQL> select * from krishnendu where marks<=50;


0 rows selected.

10. If any student fails,discard his record from the database.


ans: As per the database, no student failed.
11. Remove the address field from your table.
SQL> alter table krishnendu drop column address;
Table altered.

SQL> select * from krishnendu;

ROLL NAME BRANCH AGE MARKS


--------- -------------------- ---- ------------
1 Krish CSE 23 95
2 Bibek IT 23 95
3 Heena EEE 23 95
4 Reena ECE 23 95
5 Teena ME 23 95

12. All of you need to create emp table to do the assignments from Question 12.
ans: SQL>CREATE TABLE EMP (EMPNO NUMBER,ENAME VARCHAR2(20),JOB
VARCHAR2(20),HIREDATE DATE,SAL NUMBER,DEPTNO NUMBER);
Table Created.

SQL> select * from emp;

EMPNO ENAME JOB HIREDATE SAL DEPTNO


---------- ---------- --------- --------- ---------- ----------
7369 Smith Clerk 17-DEC-80 800 20
7499 Allen Salesman 20-FEB-81 1600 30
7521 Ward Salesman 22-FEB-81 1250 20
7566 Jones Manager 02-APR-81 2975 20
7654 Martin Salesman 28-SEP-81 1250 30
7698 Blake Manager 01-MAY-81 2850 30
7782 Clark Manager 09-JUN-81 2450 10
7788 Scott Analyst 19-APR-87 3000 20
7839 King President 17-NOV-81 5000 10
7844 Turner Salesman 08-SEP-81 1500 30
7876 Adams Clerk 23-MAY-87 1100 20
7900 James Clerk 03-DEC-81 950 30
7902 Ford Analyst 03-DEC-81 3000 20
7934 Miller Clerk 23-JAN-82 1300 10

14 rows selected.

13. Copy the contents from emp table to a new table.


ans: SQL> create table emp2 as select * from emp;
Table created.

SQL> select * from emp2;

EMPNO ENAME JOB HIREDATE SAL DEPTNO


---------- ---------- --------- --------- ---------- ----------
7369 Smith Clerk 17-DEC-80 800 20
7499 Allen Salesman 20-FEB-81 1600 30
7521 Ward Salesman 22-FEB-81 1250 20
7566 Jones Manager 02-APR-81 2975 20
7654 Martin Salesman 28-SEP-81 1250 30
7698 Blake Manager 01-MAY-81 2850 30
7782 Clark Manager 09-JUN-81 2450 10
7788 Scott Analyst 19-APR-87 3000 20
7839 King President 17-NOV-81 5000 10
7844 Turner Salesman 08-SEP-81 1500 30
7876 Adams Clerk 23-MAY-87 1100 20
7900 James Clerk 03-DEC-81 950 30
7902 Ford Analyst 03-DEC-81 3000 20
7934 Miller Clerk 23-JAN-82 1300 10

14 rows selected.

14. Show the employee record from your new table.


ans: SQL> select * from emp2;

EMPNO ENAME JOB HIREDATE SAL DEPTNO


---------- ---------- --------- --------- ---------- ----------
7369 Smith Clerk 17-DEC-80 800 20
7499 Allen Salesman 20-FEB-81 1600 30
7521 Ward Salesman 22-FEB-81 1250 20
7566 Jones Manager 02-APR-81 2975 20
7654 Martin Salesman 28-SEP-81 1250 30
7698 Blake Manager 01-MAY-81 2850 30
7782 Clark Manager 09-JUN-81 2450 10
7788 Scott Analyst 19-APR-87 3000 20
7839 King President 17-NOV-81 5000 10
7844 Turner Salesman 08-SEP-81 1500 30
7876 Adams Clerk 23-MAY-87 1100 20
7900 James Clerk 03-DEC-81 950 30
7902 Ford Analyst 03-DEC-81 3000 20
7934 Miller Clerk 23-JAN-82 1300 10

14 rows selected.

15. Show salary statement along with name of all employees whose salary>1000.
ans: SQL> select * from emp2 where sal>1000;

EMPNO ENAME JOB HIREDATE SAL DEPTNO


---------- ---------- --------- --------- ---------- ----------
7499 Allen Salesman 20-FEB-81 1600 30
7521 Ward Salesman 22-FEB-81 1250 20
7566 Jones Manager 02-APR-81 2975 20
7654 Martin Salesman 28-SEP-81 1250 30
7698 Blake Manager 01-MAY-81 2850 30
7782 Clark Manager 09-JUN-81 2450 10
7788 Scott Analyst 19-APR-87 3000 20
7839 King President 17-NOV-81 5000 10
7844 Turner Salesman 08-SEP-81 1500 30
7876 Adams Clerk 23-MAY-87 1100 20
7902 Ford Analyst 03-DEC-81 3000 20
7934 Miller Clerk 23-JAN-82 1300 10

12 rows selected.

16. How many such employees are there whose salary is within 1000 to 3000 range?
ans: SQL> select * from emp2 where sal between 1000 and 3000;
EMPNO ENAME JOB HIREDATE SAL DEPTNO
---------- ---------- --------- --------- ---------- ----------
7499 Allen Salesman 20-FEB-81 1600 30
7521 Ward Salesman 22-FEB-81 1250 20
7566 Jones Manager 02-APR-81 2975 20
7654 Martin Salesman 28-SEP-81 1250 30
7698 Blake Manager 01-MAY-81 2850 30
7782 Clark Manager 09-JUN-81 2450 10
7788 Scott Analyst 19-APR-87 3000 20
7844 Turner Salesman 08-SEP-81 1500 30
7876 Adams Clerk 23-MAY-87 1100 20
7902 Ford Analyst 03-DEC-81 3000 20
7934 Miller Clerk 23-JAN-82 1300 10

11 rows selected.

17. Give a pay hike to the employees whose salary is 1250 and 950.
ans: SQL> update emp2 set sal=sal*1.2 where sal in(1250,950);
3 rows updated.

SQL> select * from emp2;

EMPNO ENAME JOB HIREDATE SAL DEPTNO


---------- ---------- --------- --------- ---------- ----------
7521 Ward Salesman 22-FEB-81 1500 20
7654 Martin Salesman 28-SEP-81 1500 30
7900 James Clerk 03-DEC-81 1140 30

3 rows selected.

18. Suggest a meaningful name for salary hike column.


ans: SQL> alter table emp2 rename column sal to updated_sal;
Table altered.

SQL> select * from emp2;

EMPNO ENAME JOB HIREDATE UPDATED_SAL DEPTNO


---------- ---------- --------- --------- ----------- ----------
7369 Smith Clerk 17-DEC-80 800 20
7499 Allen Salesman 20-FEB-81 1600 30
7521 Ward Salesman 22-FEB-81 1500 20
7566 Jones Manager 02-APR-81 2975 20
7654 Martin Salesman 28-SEP-81 1500 30
7698 Blake Manager 01-MAY-81 2850 30
7782 Clark Manager 09-JUN-81 2450 10
7788 Scott Analyst 19-APR-87 3000 20
7839 King President 17-NOV-81 5000 10
7844 Turner Salesman 08-SEP-81 1500 30
7876 Adams Clerk 23-MAY-87 1100 20
7900 James Clerk 03-DEC-81 1140 30
7902 Ford Analyst 03-DEC-81 3000 20
7934 Miller Clerk 23-JAN-82 1300 10

14 rows selected.

You might also like