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
以上是mysql中關於刪除語句大全總結(下)的詳細內容。更多資訊請關注PHP中文網其他相關文章!