0% found this document useful (0 votes)
38 views7 pages

Print SQL

Uploaded by

Arti Kumari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views7 pages

Print SQL

Uploaded by

Arti Kumari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

CREATE DATABASE

 create database bookstore;

1
CREATE TABLE
 USE bookstore;

 DROP TABLE IF EXISTS books;


 CREATE TABLE books
(
id int unsigned NOT NULL auto_increment, # Unique ID for the record
title varchar(255) NOT NULL, # Full title of the book
author varchar(255) NOT NULL, # The author of the book
price decimal(10,2) NOT NULL, # The price of the book

PRIMARY KEY (id)


);

2
INSERT VALUES
 INSERT INTO books ( title, author, price )
 VALUES
( "JAVA", "John Smith", 100.69 ),
( "Networking", "George Orwell", 223.99 ),
( "Operating System", "L.S krishnmurti", 179.99 );

3
Search Table & Search table With Condition
 SELECT * FROM books;

 SELECT * FROM books WHERE price < 150 AND price > 100;

4
UPDATE TABLE
UPDATE books SET price = price + 100 WHERE title = 'java';

5
DELETE TABLE
DELETE FROM books WHERE title LIKE 'java%';

6
"ALTER TABLE" to add a new column
ALTER TABLE books
ADD COLUMN year INT UNSIGNED NOT NULL;
UPDATE books SET year = 2010 WHERE id = 2;

You might also like