/*
**Checktoseethethetableexistsandinitialize@objid.
*/
ifnotExists(Selectnamefromsysobjectswherename=@ObjName)
begin
select@DBName=db_name()
raiserror(15009,-1,-1,@ObjName,@DBName)
return(1)
end
Select@Script=
while(@@FETCH_STATUS-1)
begin
if(@@FETCH_STATUS-2)
begin
Select@Script=@ColName++@TypeName
if@UserTypein(1,2,3,4)
Select@Script=@Script+(+Convert(char(3),@Length)+)
elseif@UserTypein(24)
Select@Script=@Script+(+Convert(char(3),@Prec)+,
+Convert(char(3),@Scale)+)
else
Select@Script=@Script+
if(@Status&0x80)>0
Select@Script=@Script+IDENTITY(1,1)
if(@Status&0x08)>0
Select@Script=@Script+NULL
else
Select@Script=@Script+NOTNULL
if@cDefault>0
Select@Script=@Script+DEFAULT+@Const_Key
end
fetchnextfromCursor_Columninto@ColName,@ColID,@UserType,@TypeName,@Length,@Prec,@Scale,
@Status,@cDefault,@Const_Key
if@@FETCH_STATUS=0
begin
Select@Script=@Script+,
Insertinto#spscriptvalues(@Script,0)
end
else
begin
Insertinto#spscriptvalues(@Script,1)
Insertinto#spscriptvalues(),0)
end
end
CloseCursor_Column
DeallocateCursor_Column
/*Getindexinformation*/
DeclareCursor_IndexINSENSITIVECURSOR
forSelectname,IndID,statusfromsysindexeswhereobject_name(id)=@ObjName
andIndID>0andIndID255orderbyIndID/*增添了对InDid为255的判别*/
OpenCursor_Index
FetchNextfromCursor_Indexinto@ColName,@IndID,@IndStatus
while(@@FETCH_STATUS-1)
begin
if@@FETCH_STATUS-2
begin
/*
**Checktoseethethetableexistsandinitialize@objid.
*/
ifnotExists(Selectnamefromsysobjectswherename=@ObjName)
begin
select@DBName=db_name()
raiserror(15009,-1,-1,@ObjName,@DBName)
return(1)
end
Select@Script=
while(@@FETCH_STATUS-1)
begin
if(@@FETCH_STATUS-2)
begin
Select@Script=@ColName++@TypeName
if@UserTypein(1,2,3,4)
Select@Script=@Script+(+Convert(char(3),@Length)+)
elseif@UserTypein(24)
Select@Script=@Script+(+Convert(char(3),@Prec)+,
+Convert(char(3),@Scale)+)
else
Select@Script=@Script+
if(@Status&0x80)>0
Select@Script=@Script+IDENTITY(1,1)
if(@Status&0x08)>0
Select@Script=@Script+NULL
else
Select@Script=@Script+NOTNULL
if@cDefault>0
Select@Script=@Script+DEFAULT+@Const_Key
end
fetchnextfromCursor_Columninto@ColName,@ColID,@UserType,@TypeName,@Length,@Prec,@Scale,
@Status,@cDefault,@Const_Key
if@@FETCH_STATUS=0
begin
Select@Script=@Script+,
Insertinto#spscriptvalues(@Script,0)
end
else
begin
Insertinto#spscriptvalues(@Script,1)
Insertinto#spscriptvalues(),0)
end
end
CloseCursor_Column
DeallocateCursor_Column
/*Getindexinformation*/
DeclareCursor_IndexINSENSITIVECURSOR
forSelectname,IndID,status,Segmentfromsysindexeswhereobject_name(id)=@ObjName
andIndID>0andIndID255orderbyIndID
OpenCursor_Index
FetchNextfromCursor_Indexinto@ColName,@IndID,@IndStatus,@Segment
while(@@FETCH_STATUS-1)
begin
if@@FETCH_STATUS-2
begin