mysql数据库之SQL语言之DML:数据操纵语言

版权声明:酷酷的锐 https://blog.csdn.net/weixin_42057767/article/details/82430111

建表:

insert into tableName values(value1,value2,...);          
必须按照建表字段顺序赋值

insert into tableName(colName1,colName2,....) values(value1,value2,...);
给指定字段赋值

练习:
建表teacher,字段,tid int(4),tname varchar(20),tage int(2),birth date

create table teacher(tid int(4),tname varchar(20),tage int(2),birth date);

插入数据:

练习:插入一条数据  1001,高圆圆,38,'1983-10-12'

insert into teacher values(1001,'高圆圆',38,'1983-10-12');

练习:插入一条数据  1002,夜华,40

insert into teacher values(1002,'夜华',40,null);

insert into teacher(tname,tid,tage)values('白浅',1003,100);

查看是否添加进表
select * from teacher;

PS:

alter table teacher character set utf8;

创建表时直接修改默认编码集为utf8 


删除表中的数据:

delete关键字:删除表中的数据

格式:delete from tableName [where 条件]

练习1:删除表temp_t02中的所有数据。
      delete from temp_t02;

练习2:删除表中temp_t02中的tid为1001的记录。
      delete from temp_t02 where tid=1001;

练习3:删除表temp_t02中 tid为1002和地址为上海的的数据
      delete from temp_t02 where tid=1002 and address='上海';

修改表中的数据:

update关键字:修改表中的数据

格式: 
update tableName set colName1=value1[,colName2=value2] [where 条件]

练习1:修改表temp_t02中的字段address为中国。
update temp_t02 set address='中国';

练习2:修改表temp_t02中的tid为1002的address为英国,人名为micheal。
update temp_t02 set address='英国',tname='micheal' where tid=1002;

练习3:将生日为null的记录的tname改为'general'
update temp_t02 set tname='general' where tbirth is null;

练习4:将tid为1001的tbirth改为'2000-8-8';
update temp_t02 set tbirth = '2000-8-8' where tid = 1001;

练习5:将tid为1002的address改为null.
update temp_t02 set address=null where tid=1002;


 

猜你喜欢

转载自blog.csdn.net/weixin_42057767/article/details/82430111