Reputation: 103
I am using Microsoft SQL Server Management Studio.
I have a script file, like this
SET IDENTITY_INSERT [dbo].[Cars] ON
.....
Many insert statements
.....
SET IDENTITY_INSERT [dbo].[Cars] OFF
Question is if I can add something before this so that the table is cleared and updated with the new insertions?
Upvotes: 0
Views: 107
Reputation: 43896
You can use TRUNCATE TABLE
:
TRUNCATE TABLE [dbo].[Cars]
SET IDENTITY_INSERT [dbo].[Cars] ON
.....
Many insert statements
.....
SET IDENTITY_INSERT [dbo].[Cars] OFF
This removes all records from the table faster and using fewer system resources then DELETE
.
Upvotes: 4
Reputation: 32170
You can use:
TRUNCATE TABLE [dbo].[Cars]
That will delete all records in the specified table.
Note that TRUNCATE TABLE
will reset the counter on IDENTITY
columns to the initial value in the CREATE TABLE
statement. If you don't want to do that, you can use:
DELETE FROM [dbo].[Cars]
Upvotes: 3