TruncateTableWithFKByTableName

create PROCEDURE [dbo].[TruncateTableWithFK]
(
@tableName nvarchar(200)
)
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

--Delete the table  
Declare @SQL varchar(2048)   
SET @SQL = ' delete from '+ @tableName
Exec(@SQL)  

--Reset identity column  
IF EXISTS
(
SELECT *   FROM INFORMATION_SCHEMA.COLUMNS  
WHERE COLUMNPROPERTY
(  
OBJECT_ID( QUOTENAME(table_schema)+ '.' + QUOTENAME(@tableName) ),  
column_name,'IsIdentity'
) = 1  
)  
DBCC CHECKIDENT(@tableName,RESEED,0)  

posted @ 2013-07-05 10:04  FH1004322  阅读(253)  评论(0编辑  收藏  举报