為了在INSERT INTO 語句中不指定列名的情況下在列中插入值,我們必須給出與表中的列數匹配的值的數量,同時還要注意該列的資料類型.
在下面的範例中,我們插入了值,但未指定列名稱。
mysql> Insert into student values(100,'Gaurav','Ph.D'); Query OK, 1 row affected (0.08 sec) mysql> Select * from student; +--------+--------+--------+ | RollNO | Name | Class | +--------+--------+--------+ | 100 | Gaurav | Ph.D | +--------+--------+--------+ 1 row in set (0.00 sec) mysql> Insert into student values(200,'Rahul','Ph.D'),(300,'Aarav','B.tech'); Query OK, 2 rows affected (0.12 sec) Records: 2 Duplicates: 0 Warnings: 0 mysql> Select * from student; +--------+--------+--------+ | RollNO | Name | Class | +--------+--------+--------+ | 100 | Gaurav | Ph.D | | 200 | Rahul | Ph.D | | 300 | Aarav | B.tech | +--------+--------+--------+ 3 rows in set (0.00 sec)
如果我們不關心列的總數及其資料類型,MySQL 會拋出錯誤,如下所示 -
mysql> Insert into student values(400,'Raman',M.Tech); ERROR 1054 (42S22): Unknown column 'M.Tech' in 'field list' mysql> Insert into student values(400,'Raman'); ERROR 1136 (21S01): Column count doesn't match value count at row 1
以上是如何在 MySQL INSERT INTO 語句中不指定列名的情況下在列中插入值?的詳細內容。更多資訊請關注PHP中文網其他相關文章!