sql server - Why would this table allow a PK id of 0? -
in sql server 2008 r2, have table allows 0 foreign key. odd because primary key constraint specified, , identity(1,1)
descriptor used.
when first record inserted table, it's pk (regionid
) 0.
i don't have identity-insert
turned on when doing insert. (normal operation)
here's table definition:
create table [dbo].[tdfregions]( [regionid] [int] identity(1,1) not null, [regionname] [nvarchar](50) not null, [regiondescription] [nvarchar](50) not null, [active] [bit] not null, constraint [pk_tdfregions] primary key clustered ( [regionid] 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
i have been acting under assumption first record inserted table have regionid
of 1.
insert tdfregions (regionname, regiondescription, active) values ('test','test', 1)
produces:
regionid regionname regiondescription active 0 test test 1
why might happening?
edit:
ok, i've got little more background information here. ran
exec sp_msforeachtable 'alter table ? nocheck constraint all' go exec sp_msforeachtable 'delete ?' go exec sp_msforeachtable 'alter table ? check constraint all' go
to clear database when first created. have been responsible?
the reason end 0 in regionid --
when truncate table , reseed identity 0 using below command
dbcc checkident('tdfregions', reseed, 0)
if insert table insert block, regionid = 0.
Comments
Post a Comment