Copy a table 
Author Message
 Copy a table
Hi, All

In VB6, I want to design a table with the same structure
as an existing table and rename it. In addition to using
ADOX to design a table from ground, can I use some simple
code, like copy file in DOS, to create it?

Thanks in advance

andy



Sun, 27 Jun 2004 02:55:21 GMT
 Copy a table

Hi,

If you want create copy of table in same database then you
can use just SELECT INTO statement to accomplish that.

SELECT * INTO NewTableName FROM OldTableName WHERE 1=0

It will create new table with same structure as old one.
If you want to copy all records as well, then remove WHERE
clause. But be aware that NewTableName table should not
exist, or SQL statement will fail.

Val

Quote:
>-----Original Message-----
>Hi, All

>In VB6, I want to design a table with the same structure
>as an existing table and rename it. In addition to using
>ADOX to design a table from ground, can I use some simple
>code, like copy file in DOS, to create it?

>Thanks in advance

>andy
>.



Sun, 27 Jun 2004 03:06:34 GMT
 Copy a table
Also note that this won't copy your indexes/triggers/constraints, but it's
the fastest way I know of to copy the basic structure.


Quote:
> Hi,

> If you want create copy of table in same database then you
> can use just SELECT INTO statement to accomplish that.

> SELECT * INTO NewTableName FROM OldTableName WHERE 1=0

> It will create new table with same structure as old one.
> If you want to copy all records as well, then remove WHERE
> clause. But be aware that NewTableName table should not
> exist, or SQL statement will fail.

> Val

> >-----Original Message-----
> >Hi, All

> >In VB6, I want to design a table with the same structure
> >as an existing table and rename it. In addition to using
> >ADOX to design a table from ground, can I use some simple
> >code, like copy file in DOS, to create it?

> >Thanks in advance

> >andy
> >.



Sun, 27 Jun 2004 03:14:56 GMT
 Copy a table
Note that the syntax for an Oracle database would be:

CREATE TABLE <TABLENAME> as select ....

Quote:
>-----Original Message-----
>Also note that this won't copy your

indexes/triggers/constraints, but it's
Quote:
>the fastest way I know of to copy the basic structure.



>> Hi,

>> If you want create copy of table in same database then
you
>> can use just SELECT INTO statement to accomplish that.

>> SELECT * INTO NewTableName FROM OldTableName WHERE 1=0

>> It will create new table with same structure as old one.
>> If you want to copy all records as well, then remove
WHERE
>> clause. But be aware that NewTableName table should not
>> exist, or SQL statement will fail.

>> Val

>> >-----Original Message-----
>> >Hi, All

>> >In VB6, I want to design a table with the same
structure
>> >as an existing table and rename it. In addition to
using
>> >ADOX to design a table from ground, can I use some
simple
>> >code, like copy file in DOS, to create it?

>> >Thanks in advance

>> >andy
>> >.

>.



Sun, 27 Jun 2004 04:05:50 GMT
 Copy a table
Hello,

Please try the following t-sql. It's in SQL Server Book Online. Hope it
helps!
=======
Inserting Rows Using SELECT INTO
The SELECT INTO statement creates a new table and populates it with the
result set of the SELECT. The structure of the new table is defined by the
attributes of the expressions in the select list, for example:
SELECT Shippers.*, Link.Address, Link.City,
                   Link.Region, Link.PostalCode
INTO NewShippers
FROM Shippers
     JOIN LinkServer.DB.dbo.Shippers AS Link
       ON (Shippers.ShipperID = Link.ShipperID)
SELECT INTO can be used to combine data from several tables or views into
one table. It can also be used to create a new table containing data
selected from a linked server.

Allan
This posting is provided "AS IS" with no warranties, and confers no rights.



Mon, 28 Jun 2004 13:24:46 GMT
 
 [ 5 post ] 

 Relevant Pages 

1. Copying DBGrid contents to clipboard (Or copying a table from a Data component to clipboard)

2. Copying from table to table problem...

3. Stored Procedure to copy from table to table via id #

4. Copy DB Table to new Access Table

5. Copy a table to another table howto

6. Copying database tables to new tables (haviing new fields)

7. Copy ASCII Tables to New Paradox Tables

8. Copy a Table to another Table

9. New Table pointer and/or copying a tables data

10. Copying SQL Table

11. Copy Oracle tables

12. SQL Server - Copy a table from one database to another database


 
Powered by phpBB® Forum Software