emmm... 数据库基本都忘光光了。。。记一点基础知识
DML数据操作语言
- SELECT 查询某一列或者几列或者全部列的值
-
SELECT DISTINCT col FROM table
列名,获取某一列的所有值重复的只显示一次 -
WHERE
,增加判断条件 -
BETWEEN A AND B
,判断条件:在A到B之间 -
NOT BETWEEN A AND B
,判断条件:不在A到B之间 -
AND
或OR
,对判断条件进行组合 -
ORDER BY col
,根据指定的列对结果集进行排序,默认是升序ASC,降序使用DESC(字符串的话就是字母顺序) -
INSERT INTO table () VALUES ()
,表中插入一条记录。可以指定列名传递必须的列对应的值,也可以不指定列名必须传递所有的值。navicat for mysql中可以直接复制为insert语句 -
UPDATE table SET x=y WHERE
,更新表中的记录。navicat for mysql中可以直接复制为update语句 -
DELETE FROM table WHERE
,删除表中的某条记录或者所有记录。 - DELETE FROM table 或 DELETE * FROM table 删除表中的所有记录(可以有备份)。
-
DROP table
,彻底删除表(无备份) -
TRUNCATE table
,删除表的内容并释放空间但保留表结构(无备份) - 删除速度:drop > truncate > delete
SELECT id FROM commerces;
SELECT id, title FROM commerces;
SELECT DISTINCT title FROM commerces;
SELECT id FROM commerces WHERE id BETWEEN 0 AND 5;
SELECT id FROM commerces WHERE (level=1 AND state=0);
SELECT title FROM commerces ORDER BY id DESC, state ASC;
INSERT INTO commerces VALUES ('12', 'xx', 'yy', '8888', '2017-03-22 03:11:45', '2017-03-22 03:11:45', '10000', '500', '4', '1', '100', '0', '50', 'Enterprise', '0');
INSERT INTO commerces (id) VALUES ('12');
UPDATE commerces SET title='dede',description='dede' where id=1;
DELETE FROM commerces WHERE id=14;