主键不递增
我的表中的主键列有问题。我将 id 列设置为主键(我在 Management studio 中创建表并在那里设置),身份为 yes,增量为 1,种子为 1 ,但是当我尝试插入时,它不想插入(只插入一次并且不会增加 id 的值)。 该怎么办 ?这是来自 Managememt 工作室。
/****** Object: Table [dbo].[club] Script Date: 01/01/2011 22:00:04 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[club](
[id] [int] NOT NULL,
[name] [varchar](50) NOT NULL,
[id_city] [int] NOT NULL,
[street] [varchar](50) NULL,
[street_number] [nchar](10) NULL,
[descritpion] [varchar](500) NULL,
[logo_path] [varchar](50) NULL,
CONSTRAINT [PK_club] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
I have problem with primary key column in my table. I set id column to be primary key ( I create table in Management studio and set there ), is identity to yes, increment to 1, seed to 1 , but when I try to insert it doesn't want to insert ( insert just once and doesn't increment value for id ).
What to do ? This is from Managememt studio .
/****** Object: Table [dbo].[club] Script Date: 01/01/2011 22:00:04 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[club](
[id] [int] NOT NULL,
[name] [varchar](50) NOT NULL,
[id_city] [int] NOT NULL,
[street] [varchar](50) NULL,
[street_number] [nchar](10) NULL,
[descritpion] [varchar](500) NULL,
[logo_path] [varchar](50) NULL,
CONSTRAINT [PK_club] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据提供的
CREATE TABLE
语句,很明显 IDENTITY 属性未启用。它应该类似于:创建表后无法应用 IDENTITY - 该表需要删除并删除。创建的。您有几个选择:
club
表,重新添加数据。 - 使用 IDENTITY 属性创建club
表,从临时表导入行,继续插入其他数据Based on the
CREATE TABLE
statement provided, it's obvious that the IDENTITY property was not enabled. It should've resembled:IDENTITY can not be applied after the table has been created -- the table needs to be dropped & created. You have a couple of options:
club
table, re-create theclub
table with the IDENTITY property, import rows from the temp table, carry on inserting additional data由于自动增量不起作用,因此您可能没有有价值的数据。
我建议使用以下脚本重新创建您的表:
Since autoincrement doesn't work, you have probably no valuable data.
I propose to recreate your table with the following script:
主键不会自行递增,因为它是主键。
如果您希望在 SQL Server 中使用“自动增量”字段,则必须将该列设置为 身份列。
A Primary Key does not increment by itself because it's a primary key.
If you want an 'auto increment' field in SQL Server, the column has to be set as an identity column.