数据库(二)

文章目录

数据库增删改(数据,列)


数据库增删改(数据,列)

 insert语句,往表中插入数据

insert into 表名称(列1,列2,列3,.....)  values  (值1,值2,值3,....);

Insert into a(id,name,age) values (5,’小明’,18);

单条记录插入

insert  into  A(id,name,age)  values  (5,’小李’,20);

插入部分列,插入所有列,插入全部列

insert into A (Name) values ('tim');

注意!enum数据类型的列插入的数据可以枚举的顺序来表示

create  table  A(id char(20),result enum(‘优’,’差’)) engine myisam charset utf8;

Insert  into  A(id,result)  values   (1,’优’),(2,’差’),(3,null);

Insert  into  A(id,result)  values   (1,1),(2,2),(3,6);

插入一列

alter table 表名称 add 列名称 列类型;  --新增一列(列在新增时需要附带该列的类别) Alter table D add name char(4);

Alter  table  A  add    class  char(5);

 delete语句

   删除一行数据;  

  delete from 表 where 列=值(条件);

Delete from A where id = 1;

  删除A表中第二条数据

  Delete from  A  where  id = 2;

删除1,2,3,行数据

  Delete  from  A  where  id=1  or  id=2  or  id=3;

delete  from  A  where  id  in (1,2,3);

删除一个列;

alter  table 表名称 drop  列名称;

Alter table chenyu drop

Alter  table 表名称 drop  column  列名称;

 update语句

修改一列数据;

update 表名 set 列名=值(条件);

Update A set name = ‘小明’;

修改某一个数据

Update  表名  set  列名=值(改的内容)  where  列=值(改的条件);

Update A set name = ‘小红’ ,score = ‘60’ where id = 1;

update 表名 set 列名1=值,列名2=值... where 列=值;

  将A 表里第一行的name改为二蛋,age改为22;

update A set name='二蛋',age='22'    where id=1;

  修改一个列的值(一行数据中的某一个值);

  update 表名 set 列名列=值where限制条件;

update A set score= '80' where id=1;

修改一个列名;(列在修改时需要附带该列的类别)

Alter  table  表名  change    原列名  新列名  类型(字符类型(位数))

Alter  table  表名  change   column   原列名  新列名  类型(字符类型(位数))

Alter  table  A  change    ID  ID1  int(5);

Alter  table  A  change  column  ID  ID1  int(5);

1.修改A_scl表中id列为sid列,规定为整数型,位数可以输入3位;

Alter  table  A_scl  change   id  sid  int(3);

修改一个列属性;

Alter   table  表名  modify   列名  列属性;

alter table A  modify name char(50);

总结:后续持续更新数据库知识

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值