Vous êtes sur la page 1sur 11

DBMS ASSIGNMENT

RAHUL KUMAR JAIN V

1701721033137

3RD BCA – B

MCC
CREATING TABLES:

1. Create a table library with the fields : Book, ISBN_NO, Title, Year, Price,
Author_Name, Publisher_Name (set Primary Key)

Command:

create table library(Book varchar(50), ISBN_No integer


Primary key, Title varchar(50), Year integer, Price
integer, Author_Name varchar(50), Publisher_Name
varchar(50))
select * from library

Output:
2. Create a table author with the fields: Author_Name and Country

Command:

create table author(Author_Name varchar(50), Country


varchar(50))
select * from author

Output:

3. Create a table publisher with the fields: Publisher_Name and Publisher_Address


Command:

create table publisher(Publisher_Name varchar(50),


Publisher_Address varchar(50))
select * from publisher

Output:
PERFORMING QUERIES:
1. Find the title of the book in library published in the year 2000:
Command:
select title from library where Year = 2000

Output:

2. Find the titles of the book having price between 500 to 600:
Command:
select title from library where Price<600 and Price>500

Output:

3. Find the titles of the book with Author_Name and Country published in the year
2000:
Command:

select Title, author.Author_Name, author.Country from


library, author where library.Year>2000 and
library.Author_Name = author.Author_Name

Output:
4. Display the titles of the book with Author_Name and Author Country:
Command:

select Title, author.Author_Name, author.Country from


library, author where library.Author_Name =
author.Author_Name

Output:

5. Find the names of the Author from Author table where first two character of the
name are “jo”:
Command:
select Author_Name from author where Author_Name like
'Jo%'

Output:

6. Find the Author_Name from author where the second character of the name is
either ‘a’ or ‘e’:
Command:
select Author_Name from author where Author_Name like
'_e%' or Author_Name like '_a%'

Output:
7. Display the names of all publishers where address includes the sub string ‘chen’:
Command:
select Publisher_Name, Publisher_Address from publisher
where Publisher_Address like '%chen%'

Output:

8. Display all titles of books with price on ascending order:


Command:
select Title, Price from library order by Price

Output:

9. Find the average price of all the books:


Command:
select AVG(Price) as Average from library

Output:
10. Find the book with least prices:
Command:
select Title, Price from library where Price = (Select
MIN(Price) from library)

Output:

11. Find the book with maximum prices:


Command:
select Title, Price from library where Price = (Select
MAX(Price) from library)

Output:

12. Find the total price of all the books:


Command:
select SUM(Price) as Total from library

Output:

13. Find the total number of books:


Command:
select COUNT(Book) as Total_Books from library

Output:
14. Delete all books from books relation where publishing year is less than 1997:
Command:

delete from library where Year<1997


select * from library

Output:

15. Delete all books having price less than average price of books:
Command:

delete from library where Price <(Select AVG(Price) from


library)
select * from library

Output:

16. Increase the price of all books by 15%:


Command:
update library set Price = (Price)+(Price * 0.15)
select * from library

Output:
17. Increase the price of the book by 15% whose price is less than 200:
Command:
update library set Price = (Price)+(Price * 0.15) where
Price<200
select * from library

Output:

18. Display all titles of book with year in descending order of year:
Command:
select Title, Year from library order by Year desc

Output:

19. Display the title, author and publisher_name of all books published in the year
2000, 2002 and 2004:
Command:
select title, Author_Name, Publisher_Name, Year from
library where Year = 2000 or Year = 2002 or Year = 2004

Output:
20. Get the details of Indian author who have published book in year 2004:
Command:

select library.Author_Name , library.Year, author.Country


from library, author where library.Year = 2004 and
author.Country = 'India' and library.Author_Name =
author.Author_Name

Output:

21. Display the title, author and publisher of all books except those which are
published in the year 2000, 2002 and 2004:
Command:
select title, Author_Name, Publisher_Name, Year from
library where Year != 2000 and Year != 2002 and Year !=
2004

Output:

22. Get the titles of all books written by authors not living in India:
Command:
select library.Title,library.Author_Name, author.Country
from library, author where author.Country != 'India' and
library.Author_Name = author.Author_Name

Output:
23. Display the titles of books that have price greater than at least one book published
in year 2004:
Command:

select Title, Price from library where Price>some(select


Price from library where Year = 2004)

Output:

24. Display the titles of books that have price greater than all the books published in
year 2004:

Command:
select Title, Price from library where Price>all(select
Price from library where Year = 2004)

Output:

25. Display total price of all books (publisher wise):


Command:
select * from library order by Publisher_Name

Output:

Vous aimerez peut-être aussi