All Statements About CREATE TABLE Statement, INSERT INTO Statement, UPDATE SET Statement and DELETE FROM Statement

You might also like

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

7.

All statements about CREATE TABLE statement, INSERT INTO


statement, UPDATE SET statement and DELETE FROM statement.

CREATE TABLE `student_info` (

`student_id` int NOT NULL,

`studentname` varchar(45) NOT NULL,

`department` varchar(45) NOT NULL,

`birth_date` varchar(70) NOT NULL,

PRIMARY KEY (`student_id`)

INSERT INTO `student_info` VALUES

(102,'naimur','cst','2000-10-11'),(103,'sifat','EEE','1999-03-06'),(104,'abhijit','cst','2000-11-04'),
(105,'wish','civil','2001-12-10'),(106,'rifat','EEE','2000-10-06');
UPDATE student_info

SET department = 'cst'

WHERE student_id =105;


DELETE FROM student_info

WHERE studentname= 'wish' ;

CREATE TABLE `borrowing_info` (

`student_id` int NOT NULL,

`studentname` varchar(45) NOT NULL,

`borrowing_date` varchar(45) NOT NULL,

`book_id` varchar(45) NOT NULL,

`status` varchar(45) NOT NULL,

PRIMARY KEY (`student_id`)

INSERT INTO `borrowing_info` VALUES

(102,'naimur','2021-11-27','1','offline'),(103,'sifat','2021-11-29','2','offline'),(104,'abhijit','2021-12-
10','3','online'),(105,'wish','2021-12-17','4','online'),(106,'rifat','2021-12-22','5','offline');
update borrowing_info

set status = 'online'

where student_id = 103;


DELETE FROM borrowing_info

WHERE status = 'offline' ;

CREATE TABLE `rate_info` (

`student_id` int NOT NULL,


`bookname` varchar(45) NOT NULL,

`rate` varchar(45) NOT NULL,

`status` varchar(50) DEFAULT NULL,

PRIMARY KEY (`student_id`)

INSERT INTO `rate_info` VALUES

(102,'Alchemist','9','offline'),(103,'Odyssey','8','offline'),(104,'Hamlet','9','online'),
(105,'Macbeth','9','online'),(106,'King Lear ','8','offline');
update rate_info

set rate='10'

where student_id = 104;

DELETE FROM rate_info

WHERE rate = '9';


ere

CREATE TABLE `book_info` (

`student_id` int NOT NULL,

`bookname` varchar(45) NOT NULL,

`book_id` varchar(25) NOT NULL,

`borrow_duration` varchar(40) NOT NULL,

PRIMARY KEY (`student_id`)

INSERT INTO `book_info` VALUES

(102,'Alchemist','1','7days'),(103,'Odyssey','2','7days'),(104,'Hamlet','3','14days'),
(105,'Macbeth','4','14days'),(106,'King Lear ','5','7days');
update book_info

set bookname = 'Dune'

where student_id = 106;


DELETE FROM book_info

WHERE borrow_duration= '7days';

CREATE TABLE `contact_info` (


`student_id` int NOT NULL,

`email` varchar(70) NOT NULL,

`phonenumber` varchar(45) NOT NULL,

PRIMARY KEY (`student_id`),

UNIQUE KEY `email_UNIQUE` (`email`),

UNIQUE KEY `phonenumber_UNIQUE` (`phonenumber`)

INSERT INTO `contact_info` VALUES

(102,'naimur2@gmail.com','01785345678'),(103,'sifat3@gmail.com','01734237688'),
(104,'abhijit4@gmail.com','01785261388'),(105,'wish5@gmail.com','01953963657'),
(106,'rifat6@gmail.com','01744557833');
UPDATE contact_info

SET phonenumber = 01766448857

WHERE student_id = 105;


DELETE FROM contact_info

WHERE student_id= 104 ;


8. A brief description (one or two paragraphs) of the queries you have chosen
and why they are useful in the database and all queries you have write about
SELECT statements.

SELECT student_info.studentname, rate_info.rate FROM


student_info JOIN rate_info ON
student_info.student_id =rate_info.student_id

SELECT student_info.student_id,student_info.studentname,book_info.bookname
FROM student_info, book_info
WHEREstudent_info.student_id = book_info.student_id AND
book_info.bookname =
(SELECT bookname
FROM book_info
WHERE student_id = '102');

SELECT status
FROM borrowing_info
Group by ‘status’

SELECT *
FROM rate
Group by ‘rate’,’status’
HAVING ‘status’=’online’;

You might also like