SQL

DML(数据操纵语言)

2019-03-19  本文已影响9人  codeshaw
单词补充

插入单行数据

insert into 表名 [字段名列表] values(值列表);

/* 小写方式 */
insert into `student`(`studentName`,`age`,`studentNo`)
values ('张三',17,'10001');
插入多行数据

insert into 表名 [字段名列表] values(值列表1),values(值列表2),......,values(值列表n)

/* 小写方式 */
insert into `subject`(`subjectName`,`classHour`,`gradeID`)
values(`Logic Java`,220,1),('HTML',230,1),(`Java OOP`,240,2);
将查询结果更新到新表中

insert into 新表(字段1,字段2,......,字段n)
select 字段1,字段2,......,字段n
from 原表;

create table 新表(
select 字段1,字段2,......,字段n
from 原表
);

create table `phoneList`(
  select `studentName`,`phone`
  from `student`
);
更新数据记录

update 表名 set 字段1 = 值1,字段2 = 值2,......,字段n = 值n [where 条件];

update `student` set age = 20 where `studentNo` = '10001';
删除数据记录

delete table 表名 [where 条件];

delete table `student` where `studentNo` = '10001';
删除所有记录

truncate table 表名;

truncate table `student`;
上一篇 下一篇

猜你喜欢

热点阅读