有人告诉我说: declare @name varchar(50) DECLARE cur_test CURSOR FOR SELECT name FROM sysobjects where xtype='u' OPEN cur_test FETCH NEXT FROM cur_test into @name WHILE @@FETCH_STATUS =0 BEGIN exec ('truncate table '+@name) FETCH NEXT FROM cur_test into @name end close cur_test DEALLOCATE cur_test但是执行后有如下的信息: Server: Msg 170, Level 15, State 1, Line 1 Line 1: Incorrect syntax near 'Details'. Server: Msg 4712, Level 16, State 1, Line 1 Cannot truncate table 'Code' because it is being referenced by a FOREIGN KEY constraint. 第二个好像就是主外键引起的。
declare @name varchar(50)
DECLARE cur_test CURSOR FOR
SELECT name FROM sysobjects where xtype='u'
OPEN cur_test
FETCH NEXT FROM cur_test into @name
WHILE @@FETCH_STATUS =0
BEGIN
exec ('truncate table '+@name)
FETCH NEXT FROM cur_test into @name
end
close cur_test
DEALLOCATE cur_test但是执行后有如下的信息:
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'Details'.
Server: Msg 4712, Level 16, State 1, Line 1
Cannot truncate table 'Code' because it is being referenced by a FOREIGN KEY constraint.
第二个好像就是主外键引起的。
truncate table 表名