SQL语言
CREATE TABLE TABLENAME (COL_NAME1 TYPE, COL_NAME2 TYPE, ……);
TYPE |
说明 |
INT |
整数 |
CHAR(LENGTH) |
定长字符串,短于指定长度用空格填充 |
VARCHAR(LENGTH) |
变长字符串 |
DROP TABLE TABLENAME;
CREATE TABLE table1
(NAME VARCHAR(10),
SEX INT,
AGE INT,
CLASS VARCHAR(20));
CREATE TABLE table2
(ID int(11) NOT NULL auto_increment, NAME varchar(20), AGE INT, PRIMARY KEY (ID))
SELECT * FROM TABLENAME;
SELECT COL1,COL2,… FROM TABLENAME;
SELECT * FROM table1;
SELECT NAME,AGE FROM table1;
SELECT * FROM table1 LIMIT 0,5
SELECT * FROM table1 LIMIT 6,3
SELECT COL1,COL2,… FROM TABLENAME WHERE CONDITIONAL;
SELECT * FROM table1 WHERE NAME = ‘TOM’ AND AGE = 20;
SELECT * FROM table1 WHERE AGE = 21 OR AGE = 20;
SELECT * FROM table1 WHERE NAME LIKE ‘tom%’;
SELECT * FROM table1 WHERE NAME LIKE ‘%tom’;
SELECT * FROM table1 WHERE NAME LIKE ‘%tom%’;
SELECT name 姓名 FROM table1;
SELECT a.name FROM table1 a;
例如::SELECT name FROM table1 GROUP BY classid;
例如:SELECT name FROM table1 ORDER BY classid DESC;
SELECT * FROM table1,table2 WHERE table1.AGE = table2.AGE;
SELECT * FROM table1,table2 WHERE (table1.NAME = table2.NAME) AND table1.AGE= 20;
CREATE INDEX index_name
ON table_name (column_name)
CREATE UNIQUE INDEX index_name
ON table_name (column_name)
本例会创建一个简单的索引,名为 “table1index",在 table1表的 NAME 列:
CREATE INDEX table1index
ON table1 (NAME)
CREATE INDEX table1index
ON table1 (NAME DESC)
CREATE INDEX table2index
ON table2 (NAME, AGE)
INSERT INTO TABLENAME (COL1,COL2,….) VALUES (VAL1,VAL2,….);
INSERT INTO table1 (NAME,SEX,AGE,CLASS) VALUES (‘TOM’,1,20,’222’);
UPDATE TABLENAME SET CAL1=VAL1,CAL2=VAL2,… WHERE CONDITIONAL
UPDATE table1 SET CLASS = ‘333’ WHERE NAME = ‘TOM’;
DELETE FROM TABLENAME WHERE CONDITIONAL
DELETE FROM 'table1’ WHERE NAME = ‘TOM’;