SQL Structured Query Language 1 Database CREATE DATABASE

SQL Structured Query Language 1




การสราง Database ไวยากรณ CREATE DATABASE databasename; n ���� CREATE DATABASE tot; n 5
![การสราง Table ไวยากรณ CREATE TABLE tablename )column 1 datatype ]constraint[, column 2 datatype ]constraint[, การสราง Table ไวยากรณ CREATE TABLE tablename )column 1 datatype ]constraint[, column 2 datatype ]constraint[,](http://slidetodoc.com/presentation_image_h/d38bf7705a421890f63c1a1089080baf/image-6.jpg)
การสราง Table ไวยากรณ CREATE TABLE tablename )column 1 datatype ]constraint[, column 2 datatype ]constraint[, column 3 datatype ]constraint ; (…, [ n ตวอยาง CREATE TABLE employee )first varchar)15(, last varchar)20(, age number)3(, address varchar)30(, city varchar)20(, state varchar)20((; n 6

การปอนขอมล n n ไวยากรณ INSERT INTO tablename )column 1, column 2, (. . . VALUES)value 1, value 2, (. . . ; ตวอยาง INSERT INTO employee )first, last, age, address, city, state( VALUES )'Luke', 'Duke', 45, '2130 Boars Nest', 'Hazard Co', 'Georgia'(; 7

การปรบปรงขอมล n n ไวยากรณ UPDATE tablename SET columnname 1 = newvalue 1 [, “columnname 2" = "newvalue 2[. . . " WHERE column 1 OPERATOR value ]AND| OR column 2 OPERATOR value ]; ตวอยาง UPDATE phone_book SET area_code =623 WHERE prefix =979; 8

การลบขอมล n n ไวยากรณ DELETE FROM tablename WHERE column OPERATOR value [AND|OR column OPERATOR value ]; ตวอยาง DELETE FROM employee WHERE firstname ='Mike' or firstname ='Eric'; 9

การลบ Table n n n DROP statement ทใชในการลบ Table หรอยกเลก ไวยากรณ DROP TABLE tablename ; ตวอยาง DROP TABLE employee; 10

SQL Query n n n SELECT Statement GROUP BY HAVING ORDER BY การรวมเงอนไขกบ Boolean Operator IN และ BETWEEN 11

SELECT Statement n n n ประโยคคำสง SELECT ไดรบการนำไปใชในการคนหาขอมลในฐานขอมล และดงขอมลทเลอกตรงตามเกณฑทกำหนด ไวยากรณ SELECT column FROM table 1[, table 2] ]WHERE conditions ] ]GROUP BY column-list ] ]HAVING conditions ] ]ORDER BY column-list ]ASC | DESC[ [; ตวอยาง SELECT name, age, salary FROM employee WHERE name LIKE “j%”; WHERE age > 50; 12

SELECT Statement (cont. ) n เครองหมายเปรยบเทยบอนๆ (comparison operator( 13


การรวมเงอนไข Operator n n และ Boolean AND operator SELECT employee_id, name, salary FROM employee WHERE salary > =20000. 00 AND dept ='Programmer'; OR operator SELECT employee_id, name, salary FROM employee WHERE (dept' = Sales') OR (dept' = Programmer ; (' 15

IN และ BETWEEN n n IN SELECT employee_id, name, salary FROM employee WHERE name IN ("jenifer lopez", "will human"); BETWEEN SELECT employee_id, age, name, salary FROM employee WHERE age BETWEEN 30 AND 40; 16


18

19

20

21

22

23
- Slides: 23