動態創建表名

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)

你可能感兴趣的:(表名)