動態創建表名

declare @table varchar(20)
set  @table='salesfact'+rtrim(year(getdate()))
declare @sql varchar(1000)
set @sql='
if exists(select 1 from sysobjects where name='''+@table+''' and xtype=''u'')
 drop table ['+@table+']

 create table ['+@table+']
(
a int,
b char(4),
c int
)'
exec(@sql)

posted @ 2006-12-20 16:22  Nina  阅读(336)  评论(0编辑  收藏  举报