Truncate Table Foreign Key varken

DECLARE @TableName NVARCHAR(128)='TabloAdi'

BEGIN TRAN

DECLARE @NextId NUMERIC = CASE WHEN (IDENT_CURRENT(@TableName) = 1) THEN 1 ELSE 0 END
DECLARE @Sql NVARCHAR(MAX) = 'DELETE FROM [' + @TableName + ']'
EXECUTE sp_executesql @Sql
IF (@@ERROR = 0) BEGIN
DBCC CHECKIDENT (@TableName, RESEED, @NextId)
COMMIT TRAN
END ELSE BEGIN
ROLLBACK
END

 

 

Kaynak: Eduardo Cuomo