mysql删除语句大全(下)update set和alter drop

26 篇文章 6 订阅

4.update set 语句是mysql最常用的修改和更新语句,它更新信息时也会覆盖(删除)旧的信息。

A  update set 与where搭配使用,变更某些记录:

update +表名 +set+ 变更后的信息 +where子句;

例如:

update stu set birth=1988,department='中文系' where id=9    and name='张三';

注意:如果变更信息后面没有加where子句指定其变更的内容,那么update set语句就会把这个字段中的所有信息全部更新,修改。


例如:
mysql> select * from c1score;
+-------+------+
| score | s    |
+-------+------+
|    56 |    1 |
|    79 |    2 |
|    91 |    3 |
|    46 |    5 |
|    35 |    6 |
+-------+------+
5 rows in set (0.08 sec)
mysql> update c1score set score=score+8;
Query OK, 5 rows affected (0.13 sec)
Rows matched: 5  Changed: 5  Warnings: 0
mysql> select * from c1score;
+-------+------+
| score | s    |
+-------+------+
|    64 |    1 |
|    87 |    2 |
|    99 |    3 |
|    54 |    5 |
|    43 |    6 |
+-------+------+                                                                                                    
5 rows in set (0.00 sec)


5用alter语句来删除字段:
A   alter table 表名 drop 字段名;

mysql> alter table c1score drop s;
Query OK, 0 rows affected (1.80 sec)
Records: 0  Duplicates: 0  Warnings: 0
mysql> select * from c1score;
+-------+
| score |
+-------+
|    64 |
|    87 |
|    99 |
|    54 |
|    43 |
+-------+
5 rows in set (0.00 sec)
B   用alter来删除索引:
mysql> drop index idx_4a on 4a;        
Query OK, 0 rows affected (0.41 sec)        
Records:  0   Duplicates:  0   Warnings:  0

C  用alter来删除主键:
mysql> alter table sc3 drop primary key;
Query OK, 17 rows affected (1.00 sec)
Records: 17  Duplicates: 0  Warnings: 0
D 用alter来删除,更新表名:
mysql> alter table sc3 rename to gyssc;
Query OK, 0 rows affected (0.30 sec)
mysql> select * from sc3;
ERROR 1146 (42S02): Table 'trains.sc3' doesn't exist

     











评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值