sql statements
DESCRIPTION
SQL statements. SQL statement types. Data definition Data manipulation Control. Data definition statements. CREATE DATABASE CREATE TABLE. CREATE DB. CREATE DATABASE ` db_name ` [ DEFAULT [ CHARACTER SET utf8 ] [ COLLATE utf8_lithuanian_ci ] ] - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: SQL statements](https://reader035.vdocument.in/reader035/viewer/2022070401/568135cc550346895d9d30b6/html5/thumbnails/1.jpg)
![Page 2: SQL statements](https://reader035.vdocument.in/reader035/viewer/2022070401/568135cc550346895d9d30b6/html5/thumbnails/2.jpg)
Data definition Data manipulation Control
![Page 3: SQL statements](https://reader035.vdocument.in/reader035/viewer/2022070401/568135cc550346895d9d30b6/html5/thumbnails/3.jpg)
CREATE DATABASECREATE TABLE
![Page 4: SQL statements](https://reader035.vdocument.in/reader035/viewer/2022070401/568135cc550346895d9d30b6/html5/thumbnails/4.jpg)
◦ CREATE DATABASE `db_name` [DEFAULT [CHARACTER SET utf8] [COLLATE utf8_lithuanian_ci] ]
http://dev.mysql.com/doc/refman/5.1/en/create-database.html
◦ CREATE DATABASE `testing`
◦ CREATE DATABASE `testing` DEFAULT CHARSET utf8 COLLATE utf8_lithuanian_ci
![Page 5: SQL statements](https://reader035.vdocument.in/reader035/viewer/2022070401/568135cc550346895d9d30b6/html5/thumbnails/5.jpg)
CREATE TABLE `Supplier` ( `No` CHAR(5) NOT NULL, `Name` CHAR(20) NOT NULL, `State` SMALLINT, `City` CHAR(15), PRIMARY KEY (`Nr`) )
Write a SQL statement to create a table for products
![Page 6: SQL statements](https://reader035.vdocument.in/reader035/viewer/2022070401/568135cc550346895d9d30b6/html5/thumbnails/6.jpg)
ALTER TABLE name◦ ADD◦ CHANGE◦ DROP
ALTER TABLE `supplier` ADD `founded` DATE
ALTER TABLE `supplier` CHANGE `founded` `founded` TIMESTAMP
ALTER TABLE `supplier` DROP `founded`
![Page 7: SQL statements](https://reader035.vdocument.in/reader035/viewer/2022070401/568135cc550346895d9d30b6/html5/thumbnails/7.jpg)
DROP TABLE name
DROP TABLE `Detales`
![Page 8: SQL statements](https://reader035.vdocument.in/reader035/viewer/2022070401/568135cc550346895d9d30b6/html5/thumbnails/8.jpg)
INSERTSELECTUPDATEDELETE
![Page 9: SQL statements](https://reader035.vdocument.in/reader035/viewer/2022070401/568135cc550346895d9d30b6/html5/thumbnails/9.jpg)
INSERT INTO <table> (<field1>, <field2>) VALUES (<value1>, <value2>)
INSERT INTO `supplier` (`no`, `name`, `state`, `city`) VALUES (1,’Company’, 20, ‘Kaunas’)
INSERT INTO `supplier` (`no`, `name`, `state`, `city`) VALUES (2,’Company B’, 15, ‘Kaunas’), VALUES (3,’Company C’, 10, ‘Vilnius’),
![Page 10: SQL statements](https://reader035.vdocument.in/reader035/viewer/2022070401/568135cc550346895d9d30b6/html5/thumbnails/10.jpg)
SELECT <fields> FROM <table>
SELECT `name`, `state` FROM `supplier`
All entries in table supplier
![Page 11: SQL statements](https://reader035.vdocument.in/reader035/viewer/2022070401/568135cc550346895d9d30b6/html5/thumbnails/11.jpg)
SELECT <fields> FROM <table> [WHERE <clause>]
SELECT `name`, `state` FROM `supplier` WHERE (`city`='Vilnius‘) OR (`city`=‘Kaunas‘)
![Page 12: SQL statements](https://reader035.vdocument.in/reader035/viewer/2022070401/568135cc550346895d9d30b6/html5/thumbnails/12.jpg)
SELECT <fields> FROM <table> [WHERE <clause>] [ORDER BY <fields> ]
SELECT `name`, `state` FROM `supplier` WHERE `state`>5 ORDER BY `city` DESC
![Page 13: SQL statements](https://reader035.vdocument.in/reader035/viewer/2022070401/568135cc550346895d9d30b6/html5/thumbnails/13.jpg)
SELECT <fields> FROM <table> [WHERE <clause>] [ORDER BY <fields> ]
[LIMIT [<start>], <count> ]
SELECT `name`, `state` FROM `supplier` WHERE `state`>5 ORDER BY `city` DESC
LIMIT 1, 3
![Page 14: SQL statements](https://reader035.vdocument.in/reader035/viewer/2022070401/568135cc550346895d9d30b6/html5/thumbnails/14.jpg)
UPDATE <table> SET <field1>=<value1>[, <field2>=<value2> ] [WHERE <clause>] [LIMIT [<start>], <count> ]
UPDATE `supplier` SET `stare`=50 WHERE `city`=‘Vilnius’
![Page 15: SQL statements](https://reader035.vdocument.in/reader035/viewer/2022070401/568135cc550346895d9d30b6/html5/thumbnails/15.jpg)
DELETE FROM <table> [WHERE <clause>] [LIMIT [<start>], <count> ]
DELETE FROM `supplier` WHERE `No`=3 LIMIT 1
![Page 16: SQL statements](https://reader035.vdocument.in/reader035/viewer/2022070401/568135cc550346895d9d30b6/html5/thumbnails/16.jpg)
[email protected] [email protected]
Download sample database:◦ tiny.lt/sql1
Import it to MySQL
Write SQL statements to select information for the following questions
Save statements to a text file
All clients from London
Employee list, sorted by last name
List of orders made in 2003
Average price of 1:10 scale products
Sum of payments, made in 2004 by client no. 114