duplicating an existing table
Posted in 1999
Topics: General Discussion
How can I duplicate an existing table? (I don't need the data inside, I
just want another table with the same schema). I know I can dump the
schema with dbschema and edit the file to change the table name, but I
was wondering if there's a shortcut using SQL.
Thank you
--
Free audio & video emails, greeting cards and forums
Talkway - http://www.talkway.com - Talk more ways (sm)
makojoe wrote:
>
> How can I duplicate an existing table? (I don't need the data inside, I
> just want another table with the same schema). I know I can dump the
> schema with dbschema and edit the file to change the table name, but I
> was wondering if there's a shortcut using SQL.
No but here is an awk script that you can use with either dbschema or
myschema.ec:
#rename.awk
/create table/{
if ( $3 == "*.*" ) {
split($3, a, "." );
printf( "%s.%s\\n", a[1], NewName );
} else {
printf( "create table %s\\n", NewName );
}
next;
}
/CREATE TABLE/{
if ( $3 == "*.*" ) {
split($3, a, "." );
printf( "%s.%s\\n", a[1], NewName );
} else {
printf( "CREATE TABLE %s\\n", NewName );
}
next;
}
{
print $0;
}
You execute this by setting NewName on the commandline, thus:
dbschema -d mydbs -t oldtable |awk -v NewName=new_table_name -f rename.awk
Art S. Kagel