MySQL 表中僅設定一個列為自動增長的插入方式?


我們首先建立一個表:

mysql> create table DemoTable
   -> (
   -> StudentId int NOT NULL AUTO_INCREMENT,
   -> PRIMARY KEY(StudentId)
   -> );
Query OK, 0 rows affected (0.60 sec)

使用 insert 命令在表中插入一些記錄。在此處,我們插入了一個值,但由於它是自動增長,因此,可以看見預設值:

mysql> insert into DemoTable(StudentId) values(0);
Query OK, 1 row affected (0.18 sec)

使用 select 語句顯示錶中的所有記錄:

mysql> select *from DemoTable;

這將會生成以下輸出。預設自動增長值為 1,第一個值可見:

+-----------+
| StudentId |
+-----------+
|         1 |
+-----------+
1 row in set (0.00 sec)

更新日期:2019 年 7 月 30 日

98 瀏覽

開啟你的 職業生涯

完成課程獲得認證

開始
廣告
© . All rights reserved.