fetch next from cursorname into @tablename1, @tabledescription, @columnname, @columndescription,@identityflag, @keyflag, @columntype, @typelength, @nullflag, @columndefault,@indexname
if @@fetch_status<>0
break
if @tablename1 is not null and @tablename1<>' '
select @tablename=@tablename1
if @columntype='nvarchar' or @columntype='nchar'
select @typelength=@typelength/2
if @typelength>4000
select @typelength=4000
if @columntype='varchar' or @columntype='nvarchar' or @columntype='char' or @columntype='nchar'
select @columntype=@columntype+'('+ltrim(str(@typelength))+')'
if @nullflag='√'
select @nullflag=''
else
select @nullflag='not null'
if @columndefault<>''
begin
if @columntype='int' or @columntype='tinyint' or @columntype='smallint'
select @columndefault='default '+@columndefault
else
select @columndefault='default '+char(39)+@columndefault+char(39)
end
if @identityflag='√'
select @identityflag='identity(1,1)'
else
select @identityflag=''
if @keyflag='√'
select @keyflag='primary key '
else
select @keyflag=''
if @tablename1 is not null and @tablename1<>' '
begin
print @tablename
print 'create table '+ @tablename+'('+@columnname+' '+@columntype+' '+@nullflag+' '+@identityflag+
' '+ @keyflag+' '+@columndefault +')'
if exists(select name from sysobjects where name=@tablename and type='u')
exec ('drop table '+ @tablename)
exec ('create table '+ @tablename+'('+@columnname+' '+@columntype+' '+@nullflag+' '+@identityflag+
' '+ @keyflag+' '+@columndefault +')')
if @tabledescription is not null and @tabledescription<>' '
exec sp_addextendedproperty 'ms_description', @tabledescription, 'user', dbo, 'table', @tablename
if @columndescription is not null and @columndescription<>' '
exec sp_addextendedproperty 'ms_description', @columndescription, 'user', dbo, 'table', @tablename, 'column', @columnname
end
else
begin
exec (' alter table '+@tablename +' add '+@columnname+' '+@columntype+' '+@identityflag+' '+@columndefault)
if @columndescription is not null and @columndescription<>' '
exec sp_addextendedproperty 'ms_description', @columndescription, 'user', dbo, 'table', @tablename, 'column', @columnname
if @nullflag='not null'
exec (' alter table '+@tablename +' alter column '+@columnname+' '+@columntype+ ' not null')
if @keyflag='primary key '
exec (' alter table '+@tablename +' add constraint '+'pk_'+@tablename+'_'+@columnname+' '+' primary key('+@columnname+')')
&n