mysql中关于删除语句大全总结(下)


本文摘自PHP中文网,作者黄舟,侵删。

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

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

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

例如:

1

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

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

例如

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

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 字段名;

1

2

3

4

5

6

7

8

9

10

11

12

13

14

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来删除索引:

1

2

3

mysql> drop index idx_4a on 4a;   

Query OK, 0 rows affected (0.41 sec)   

Records: 0  Duplicates: 0  Warnings: 0

C 用alter来删除主键:

1

2

3

mysql> alter table sc3 drop primary key;

Query OK, 17 rows affected (1.00 sec)

Records: 17  Duplicates: 0  Warnings: 0

D 用alter来删除,更新表名:

1

2

3

4

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

以上就是mysql中关于删除语句大全总结(下)的详细内容,更多文章请关注木庄网络博客!!

相关阅读 >>

关于mysql触发器的问题

hadoop跟mysql的区别是什么?

mysql安装在哪儿怎么查看?

我所理解的mysql之二:索引

mysql怎么查两个表的交集

mysql的组成部分有哪些

mysql,navicat怎么设置主键自增

mysql数据库中修改语句的语法是什么

怎么查看mysql的安装路径?

mysql存储过程怎么写

更多相关阅读请进入《mysql》频道 >>


数据库系统概念 第6版
书籍

数据库系统概念 第6版

机械工业出版社

本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...