You are on page 1of 4

SESCOM , DAHISAR(E)

SYBCA SEM-III
Riya Yadav

Q1)Consider the given relation book and answer the following .


Acc_no P_year Title Price

A101 1982 Software Testing 499


A102 1995 Database System 729
A103 1990 Compiler 399
A104 1991 Introduction to Algorithm 550
A105 1989 Data Structures 350

Ans)
CREATE TABLE `book` (‘Acc_no’ primary key,
‘P_year’ VARCHAR(50),
‘Title’ VARCHAR(50),
‘Price’ VARCHAR(50) );

INSERT INTO `book` (`Acc_no`, `P_year`, `Title`, `Price`) VALUES ('A101', '1982', 'Software
Testing', '499');

INSERT INTO `book` (`Acc_no`, `P_year`, `Title`, `Price`) VALUES ('A102', '1995', 'Database
System', '729');

INSERT INTO `book` (`Acc_no`, `P_year`, `Title`, `Price`) VALUES ('A103', '1990', 'Compiler', '399');

INSERT INTO `book` (`Acc_no`, `P_year`, `Title`, `Price`) VALUES ('A104', '1991', 'Introduction to
Algorithm', '550');

INSERT INTO `book` (`Acc_no`, `P_year`, `Title`, `Price`) VALUES ('A105', '1989', 'Data
Structures', '350');

Q) Find the details of all the books

Ans )
SELECT * FROM `book`
Acc_no P_year Title Price

A101 1982 Software Testing 499


A102 1995 Database System 729
A103 1990 Compiler 399
A104 1991 Introduction to Algorithm 550
A105 1989 Data Structures 350

Q) Display the publisher year and title of the book.


Ans)
SELECT `P_year`, `Title` FROM `book`;

P_year Title

1982 Software Testing

1995 Database System

1990 Compiler

1991 Introduction to Algorithm

1989 Data Structures

Q) Display the price of the book.

Ans)
SELECT `Price` FROM `book`;
Price
499
729
399
550
350

Q) Display the details of the book when the price is the greater than 499.
Ans)
SELECT * FROM `book` WHERE price>499;

Acc_n P_yea Title Price


o r
A102 1995 Database System 729
A104 1991 Introduction to Algorithm 550

Q) List all the title mad account number of the “book” relation.

Ans)
SELECT `Acc_no`,`Title` FROM `book`;
Acc_no Title
A101 Software Testing

A102 Database System

A103 Compiler

A104 Introduction to
Algorithm

A105 Data Structures

Q) List the title of the book whose price is greater the 550.
a) SELECT `Title` FROM `book` WHERE price>550;
Title
Database System

Q2) Create two table of ypur own with two column and five records and perform the following
A) Divison operator
B) Union operator
C) Intersect operator
D) Difference operator
E) Cartesian product
Ans)

Create TABLE books(REATE TABLE books (


id serial,
title varchar(100) NOT NULL,
author varchar(100) NOT NULL,
published_date timestamp NOT NULL,
name char(12),
PRIMARY KEY (id),
UNIQUE (name )
);

INSERT INTO books


(id, title, author, published_date, isbn)
VALUES
(1, 'My First SQL Book', 'Mary Parker', '2012-02-22 12:08:17.320053-03', '981483029127'),
(2, 'My Second SQL Book', 'John Mayer', '1972-07-03 09:22:45.050088-07', '857300923713'),
(3, 'My First SQL Book', 'Cary Flint', '2015-10-18 14:05:44.547516-07', '523120967812');

CREATE TABLE reviews (


id serial,
book_id integer NOT NULL,
reviewer_name varchar(255),
content varchar(255),
rating integer,
published_date timestamp DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id),
FOREIGN KEY (book_id)
REFERENCES books(id)
ON DELETE CASCADE )

INSERT INTO reviews


(id, book_id, reviewer_name, content, rating,
published_date)
VALUES
(1, 1, 'John Smith', 'My first review', 4, '2017-12-10 05:50:11.127281-02'),
(2, 2, 'John Smith', 'My second review', 5, '2017-10-13 15:05:12.673382-05'),
(3, 2, 'Alice Walker', 'Another review', 1, ‘2017-10-22 23:47:10.407569-07');

A) Divison operator

B) Union operator
Ans)
SELECT * FROM books UNION SELECT * FROM reviews

C) Intersect operator
D) Difference operator
E) Cartesian product

You might also like