Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

In Code-----Copy A Table with Structure Only 1

Status
Not open for further replies.

vedicman

Programmer
Sep 5, 2003
128
US
In a code module, I want to make a copy of a table, with the structure only containing no data. Will someone kindly provide a code sample of how to do it?

Thanks......Franco
 
Create a query or run the following SQL code thus:

docmd.RunSQL "select * into table2 from table where 1=2"

Because 1 will never equal 2, no rows are copied across.

John
 
JOHN

Simple but effective. Works like a charm!

Thanks Franco
 
Franco

The only disadvantage of this method is that it won't copy the primary or foreign keys, referential integrity, field or table properties (eg descriptions, validation rules) across.

John
 
Hi Guys,

In Query Analyser, why don't you open up the object browser, right click the table that you want to use as a template, select Script Object to clipboard > create. Paste it wherever and just change the Table name. That way you get all the PK's and indexes that the parent table too.

Cheers

Skiboy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top