mirror of https://github.com/dunwu/db-tutorial.git
🚚 mysql DML 语句示例
parent
6dae2fe3c5
commit
36e4dc2f21
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* Mysql DML 语句示例
|
||||
* @author Zhang Peng
|
||||
* @date 2018/4/28
|
||||
*/
|
||||
#############################################################
|
||||
# 向表中插入新记录
|
||||
#############################################################
|
||||
|
||||
-- 不指定列名方式插入记录
|
||||
INSERT INTO `user`
|
||||
VALUES (1, 'root', 'root', 'xxxx@163.com');
|
||||
|
||||
-- 指定列名方式插入记录
|
||||
INSERT INTO `user`(`username`, `password`, `email`)
|
||||
VALUES ('admin', 'admin', 'xxxx@163.com');
|
||||
|
||||
#############################################################
|
||||
# 删除表中的记录
|
||||
#############################################################
|
||||
|
||||
-- 删除符合条件的记录
|
||||
DELETE FROM `user`
|
||||
WHERE `username` = 'admin';
|
||||
|
||||
#############################################################
|
||||
# 更新表中的记录
|
||||
#############################################################
|
||||
|
||||
-- 更新记录
|
||||
UPDATE `user`
|
||||
SET `username`='robot', `password`='robot'
|
||||
WHERE `username` = 'root';
|
||||
|
||||
#############################################################
|
||||
# 查询表中的记录
|
||||
#############################################################
|
||||
|
||||
-- 查询表中的记录
|
||||
SELECT `username`, `password` FROM `user`
|
||||
WHERE `id` = 1;
|
||||
|
||||
-- 查询表中的所有记录
|
||||
SELECT * FROM `user`;
|
||||
|
||||
-- 查询表中的不重复记录
|
||||
SELECT DISTINCT `username`
|
||||
FROM `user`;
|
Loading…
Reference in New Issue