日期:2014-05-17 浏览次数:20496 次
--建表--------------------------
IF object_id('T1000','U') IS NOT NULL
DROP TABLE T1000
DECLARE @cols NVARCHAR(MAX)
SET @cols = STUFF(( SELECT xh + ''
FROM ( SELECT TOP 1000
', col_' + RIGHT('000'
+ CAST(ROW_NUMBER() OVER ( ORDER BY GETDATE() ) AS VARCHAR),
4) + ' int ' xh
FROM sys.objects a ,
sys.objects b
) t
ORDER BY xh
FOR
XML PATH('')
), 1, 1, '')
DECLARE @create_table_sql NVARCHAR(MAX)
SET @create_table_sql = ' CREATE TABLE T1000 ( ' + REPLACE(@cols, ',', ',' + CHAR(13) + CHAR(10)) + ' ) '
--PRINT @create_table_sql
EXEC (@create_table_sql)
GO
SELECT * FROM T1000
--循环插入80条测试数据-----------------------------------------------------
DECLARE @insert NVARCHAR(max)
SET @insert = ' INSERT INTO T1000 ' + CHAR(13) + CHAR(10) + ' SELECT '
+ STUFF(( SELECT xh + ''
&n