想知道是否有一个速记版本可以将新记录插入到启用了主键的表中?(即不必在查询中包含键列)假设键列称为 ID,其他列是 Fname、Lname 和网站
Wondering if there is a shorthand version to insert a new record into a table that has the primary key enabled? (i.e. not having to include the key column in the query) Lets say the key column is called ID, and the other columns are Fname, Lname, and Website
$query = "INSERT INTO myTable VALUES ('Fname', 'Lname', 'Website')";
使用 DEFAULT 关键字:
Use the DEFAULT keyword:
$query = "INSERT INTO myTable VALUES (DEFAULT,'Fname', 'Lname', 'Website')";
此外,您可以指定列,(这是更好的做法):
Also, you can specify the columns, (which is better practice):
$query = "INSERT INTO myTable
(fname, lname, website)
VALUES
('fname', 'lname', 'website')";
参考:
这篇关于PHP mySQL - 将新记录插入表中,主键自动递增的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!