CChoks
asked on
Defncopy Question
I am using defncopy to copy the table definition out of a database but all i seem to be getting is an almost empty file that says /* ### DEFNCOPY: END OF DEFINITION */. i followed the parameters exactly but i cant seem to get the definition out...anyone know why?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The following procedure could be useful in determining the structure of a table
Syntax: exec sp_table "tableName"
Here is the text of the sp.
create procedure sp_table
@tabname varchar(30)
as
declare @max tinyint,
@j tinyint,
@msg varchar(255)
select @max=max(colid)
from syscolumns
where id = object_id(@tabname)
if (@max is null)
begin
raiserror 20001 "No such table"
return 1
end
select @msg = "create table " + @tabname + "
("
print @msg
select @j = 1
while (@j <= @max)
begin
if not exists
(
select *
from syscolumns c,
systypes t
where c.id = object_id(@tabname)
and c.usertype *= t.usertype
and c.colid=@j
)
begin
select @j=@j+1
continue
end
select @msg = " " + c.name + " " + t.name
+ substring(" (" + convert(varchar(3), c.length) + ")", 1,
1 + 6 * (charindex(t.name, "varchar/varbinary")))
+ substring(" null", 1, 1 + 5 *
(charindex(convert(varchar (3),c.stat us), "8")))
from syscolumns c,
systypes t
where c.id = object_id(@tabname)
and c.usertype *= t.usertype
and c.colid=@j
if @j != @max
select @msg = @msg + ","
print @msg
select @j=@j+1
end
print ")"
Syntax: exec sp_table "tableName"
Here is the text of the sp.
create procedure sp_table
@tabname varchar(30)
as
declare @max tinyint,
@j tinyint,
@msg varchar(255)
select @max=max(colid)
from syscolumns
where id = object_id(@tabname)
if (@max is null)
begin
raiserror 20001 "No such table"
return 1
end
select @msg = "create table " + @tabname + "
("
print @msg
select @j = 1
while (@j <= @max)
begin
if not exists
(
select *
from syscolumns c,
systypes t
where c.id = object_id(@tabname)
and c.usertype *= t.usertype
and c.colid=@j
)
begin
select @j=@j+1
continue
end
select @msg = " " + c.name + " " + t.name
+ substring(" (" + convert(varchar(3), c.length) + ")", 1,
1 + 6 * (charindex(t.name, "varchar/varbinary")))
+ substring(" null", 1, 1 + 5 *
(charindex(convert(varchar
from syscolumns c,
systypes t
where c.id = object_id(@tabname)
and c.usertype *= t.usertype
and c.colid=@j
if @j != @max
select @msg = @msg + ","
print @msg
select @j=@j+1
end
print ")"
the best way to remove it could be to run a shell command on the ouptut file ..
cat Outfile.txt | grep -v "DEFNCOPY: END OF DEFINITION" > tmp
mv tmp outfile.txt
thanks.