日期:2014-05-17 浏览次数:20378 次
SELECT 'TRUNCATE TABLE ' + NAME FROM sysobjects s WHERE s.xtype='u'
SELECT 'INSERT INTO ' + NAME + ' SELECT * FROM ' + '[newdate].dbo.' + NAME FROM sysobjects s WHERE s.xtype='u'--插入数据
TRUNCATE TABLE 表名
set identity_insert 表名 on
INSERT INTO 表名 ([FId],[字段1],[字段2],[字段3],[字段4],[字段5]) SELECT [FId],[字段1],[字段2],[字段3],[字段4],[字段5] FROM [服务名].数据库名.dbo.表名
set identity_insert 表名 off
DECLARE @s NVARCHAR(4000)
SET @s = ''
SELECT @s = @s + ',' + QUOTENAME(name)
FROM syscolumns
WHERE id = OBJECT_ID('表名')
AND name NOT IN ( '不希望显式的列' )
SET @s = STUFF(@s, 1, 1, '')
EXEC('select '+@s+' from 表名 ')