source - http://stackoverflow.com/a/27523976
SQL Server
-insert/write into identity field -disable all constraints for table
1
2
3
4
5
6
7
--source - http://stackoverflow.com/a/20249170
--disable all constraints for a table
ALTER TABLE Toys NOCHECK CONSTRAINT ALL
--disable all constraints for ALL tables
EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT ALL";
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
--disable all constraints for ALL tables
EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT ALL";
--delete all from table
delete from [Toys]
--enable to write @ IDENTITY field
SET IDENTITY_INSERT Toys ON
GO
--bulk insert
INSERT INTO [Toys]
([Toy_ID], [Toy_Language_ID], [Toy_SEO_ID], [Toy_Source])
VALUES
(1, 1, 1, ''),
(2, 2, 1, '');
GO
--re-enable IDENTITY field
SET IDENTITY_INSERT Toys OFF
GO
--enable all constraints
EXEC sp_msforeachtable "ALTER TABLE ? WITH CHECK CHECK CONSTRAINT ALL";
origin - http://www.pipiscrew.com/?p=2785 sql-identity-field-constraints-for-a-table