Except for any other errors, script, or settings, etc that are not described, there shouldn't be any reason why this shouldn't work. Here is a sample I've put together that would demonstrate its success.
set nocount on;
go
-- create the tables
drop table [Car];
drop table [Detail];
drop table [owner]
go
create table dbo.[Owner]
(OwnerID INT IDENTITY (1,1) NOT NULL PRIMARY KEY
, OwnerDescription varchar(35) NOT NULL
)
create table dbo.[Detail]
(DetailID INT IDENTITY (1,1) NOT NULL PRIMARY KEY
, OwnerID INT NOT NULL
, DetailDescription varchar(35) NOT NULL
)
create table dbo.[Car]
(CarID INT IDENTITY (1,1) NOT NULL PRIMARY KEY
, DetailID INT NOT NULL
, CarDescription varchar(35) NOT NULL
)
go
-- create fk constraints
ALTER TABLE dbo.[Detail]
ADD CONSTRAINT FK_Detail_Owner FOREIGN KEY (OwnerID)
REFERENCES dbo.[Owner] (OwnerID) ;
ALTER TABLE dbo.[Car]
ADD CONSTRAINT FK_Car_Detail FOREIGN KEY (DetailID)
REFERENCES dbo.[Detail] (DetailID) ;
GO
-- insert first set of data to consume first identity key values
INSERT INTO [dbo].[Owner] ([OwnerDescription])
VALUES ('Some Owner')
INSERT INTO [dbo].[Detail] ([DetailDescription], OwnerID)
VALUES ('Some Detail', 1)
INSERT INTO [dbo].[Car] ([CarDescription], DetailID)
VALUES ('Some Car', 1)
go
-- examine the data
select * from [Owner]
select * from [Detail]
select * from [Car]
go
-- remove the data with standard delete (because truncate won't work with FKs)
delete from [Car];
delete from [Detail]
delete from [Owner]
go
-- insert second set of data to consume second identity key values
INSERT INTO [dbo].[Owner] ([OwnerDescription])
VALUES ('Some Owner')
INSERT INTO [dbo].[Detail] ([DetailDescription], OwnerID)
VALUES ('Some Detail', 2)
INSERT INTO [dbo].[Car] ([CarDescription], DetailID)
VALUES ('Some Car', 2)
go
-- examine the data
select * from [Owner]
select * from [Detail]
select * from [Car]
go
-- remove the data with standard delete (because truncate won't work with FKs)
delete from [Car];
delete from [Detail]
delete from [Owner]
go
-- reseed the values to 0
dbcc checkident ('Owner', reseed, 0)
dbcc checkident ('Detail', reseed, 0)
dbcc checkident ('Car', reseed, 0)
go
-- reinsert to demonstrate the reseed works
INSERT INTO [dbo].[Owner] ([OwnerDescription])
VALUES ('Some Owner')
INSERT INTO [dbo].[Detail] ([DetailDescription], OwnerID)
VALUES ('Some Detail', 1)
INSERT INTO [dbo].[Car] ([CarDescription], DetailID)
VALUES ('Some Car', 1)
go
-- examine the data
select * from [Owner]
select * from [Detail]
select * from [Car]
go
idvalue you can just usetruncate. That said this works for mecreate table Car(Id int identity); insert into Car default values; insert into Car default values; select * from Car; delete from Car;DBCC CHECKIDENT ('Car', RESEED, 0);insert into Car default values;select * from Car; drop table Car– Martin Smith Jan 12 '12 at 18:29