如何在只有一个自动增量列的表中插入一行? [英] How to insert a row into a table that has only a single autoincrement column?

查看:59
本文介绍了如何在只有一个自动增量列的表中插入一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表只有一个称为 id 的列.此列是一个自动递增的键(我正在使用它进行排序).我想做类似的事情:insert into sequencer;但这给我SQL错误,因为我想我需要有一个values部分.但是表中没有其他列,我希望 id 列自动递增.我也不想仅仅通过添加另一个虚拟列来破解它.谢谢.

My table has only a single column calld id. This column is an autoincrementing key (I am using it for sequencing). I want to do something like: insert into sequencer; but this gives me SQL errors because I guess I need to have a values portion. But there are no other columns in the table and I want the id column to be autoincremented. I'd also rather not hack this by just adding another dummy column. Thanks.

推荐答案

INSERT INTO table SET id = NULL;

INSERT INTO table VALUES (NULL);

在自动增量列中插入NULL时,mysql将改为生成一个新数字.

When inserting NULL into an auto-increment column, mysql will generate a new number instead.

这篇关于如何在只有一个自动增量列的表中插入一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆