I have two separate commands that do the task, but I want to put them into one. First delete the data from the table and when finished reset the ID to 0
sqlcmd command to delete:
sqlcmd -S SQLServidor -d database -q "DELETE FROM TableName WHERE ID IS NOT NULL"
Command to reset the ID to 0:
sqlcm -S SQLServidor -d database -Q "USE database DBCC CHECKIDENT(TableName, RESEED, 0)" and exit
I want to put both queries in a single .bat file
Greetings.
You can write the whole query, separating each clause by
;
:Anyway, I have a few comments for you:
WHERE ID IS NOT NULL
I understand that it is redundant, if itID
is himIDENTITY
it should not be able to beNULL
IDENTITY
of the table already starts from1
, you can achieve a similar effect to the two commands, simply usingTRUNCATE TableName