You are on page 1of 3

1 .Create a Table as workers and the details are { S.

No, Name, Designation,


Branch }
Perform the following commands:

create table employee(SNo number,Name varchar(20),Designation varchar(20),Branch


varchar(20));

insert into employee values(1,'AAA','Professor','cse');


insert into employee values(2,'BBB','technician','cse');
insert into employee values(3,'CCC','HOD','civil');

Alter the table by adding a column Salary


alter table employee add(Salary number);

Alter the table modifying the column Name


alter table employee modify ( Name varchar(20));

Describe the table employee


desc employee;

Copy the table employee as emp


create table emp as select * from employee;

Truncate the table


truncate table employee;

Delete the Second row from the table


delete employee where name='BBB';

Drop the table


drop table employee;

2. Create the following tables


student_details {register_no, student_name, DOB, address, city}
mark_details {register_no, mark1, mark2, mark3, total }

create table student_details(register_nonumber,student_namevarchar(20),DOB


number,addressvarchar(20),city varchar(10));

insert into student_details values(161,'Anu',10-3-1998,'VOCnagar','Tuty');


insert into student_details values(162,'Banu',11-7-1999,'Annanagar','Chennai');
insert into student_details values(163,'Abi',20-6-1997,'Balajinagar','Tcr');

create table mark_details(register_no number,mark1 number,mark2 number,mark3


number,total number);

insert into mark_details values(161,89,90,88,267);


insert into mark_details values(162,70,80,75,225);
insert into mark_details values(163,80,90,87,257);

? Display only those rows whose total ranges between 250 and 300.
select * from mark_details where total between 250 and 300;

? Drop the table mark_details and Delete the row whose register_no=161.
delete mark_details where register_no=161;
drop table mark_details;

? Display all details whose names begins with 'a'.


select * from student_details where student_name like 'A%';
6. (a). Create a table as book (sl.no, book_name, author_name,price,
edition,publisher_name ).

create table book(s1.no number,book_namevarchar(10),author_namevarchar(10),price


number,editionnumber,publisher_namevarchar(10));

Perform the following operations:


? Insert minimum ten tuples in book table
insert into book values(1,'java','Silber',250,6,'AAA');
insert into book values(2,'python','Silber',275,6,'AAA');
insert into book values(3,'C','Silber',250,6,'AAA');
insert into book values(4,'C++','Silber',250,6,'AAA');
insert into book values(5,'html','Silber',250,6,'AAA');
insert into book values(6,'poni','kalki',250,6,'AAA');
insert into book values(7,'paathip','Silber',250,6,'AAA');
insert into book values(8,'thenali','Silber',125,6,'AAA');
insert into book values(9,'good','barathi',190,6,'AAA');
insert into book values(10,'alpha','barath',195,6,'AAA');

? Commit the table book


commit;

? Create a save point for the table book as B


savepoint B;

? Rollback the table book after inserting 4 & 5 row


rollback B;

? Define Grant & Revoke

Definition of Grant:
The command is use to give user access privileges to a database.
Syntax: GRANT SELECT ,UPDATE ON MY_TABLE TO SOME_USER,ANOTHER_USER
example:GRANT SELECT ON USER TO 'Tom' @ Local cost:

Definition of Revoke:
It is useful to back permission from to user.
Syntax: REVOKE privilege_name on object_name from{user_name/PUBLIC role_name}
example:REVOKE SELECT,UPDATE ON STUDENT,FROM BCA MCA

Consider the following relational schema:


Employee( empno, name, office, age )
Books ( isbn, title, authors, publisher )
Loan ( empno, isbn, date )

Write the following queries in SQL:

create table employee (empno number primary,name varchar(20),office varchar(20),age


number);
insert into employee values(1,'AAA','XXX',30);
insert into employee values (2,'BBB','YYY',45);
insert into employee values (3,'CCC','ZZZ',56);
insert into employee values (4,'ddd','ZZY',57);

create table book(isbn varchar(13) primary,title varchar(10),author


varchar(10),publisher varchar(10));
insert into book values(1234,'barbie','jimmy','jack');
insert into book values(5678,'ben','sam','McGraw-Hill ');
insert into book values(1256,'dora','buji','thara');

create table loan(empno int ,isbn varchar(13),sdate number,foreign key(empno,isbn)


references employee(empno),book_i(isbn);
insert into loan values(1,1234,12);
insert into loan values(2,5678,13);
insert into loan values(2,1234,13);
insert into loan values(3,1256,14);
insert into loan values(3,1234,13);
insert into loan values(4,5678,13);

Print the names of employees who have borrowed any books published by McGraw-Hill
select name from employee e,book b,loan l where e.empno=l.empno and l.isbn=b.isbn
and b.publisher='McGrawHill';

Print the names of employees who have borrowed all books published by McGraw-Hill.
select name from employee where empno in (select emp_no from book_i natural join
loan where publisher ='jam');

For each publishers, print the names of employees who have borrowed more than five
books of that publisher.
select name from employee where empno in (select emp_no from book_i natural join
loan where publisher in (select publisher from book_i natural join loan group by
publisher having count (publisher)>5));

You might also like