Copying the structure of a table into a temporary table without constraint and identities

Copying the structure of a table into a temporary table without constraint and identities

Post by Luke Jange » Fri, 04 Apr 2003 07:21:21



Dear Gurus,

Is there anyway I can copy the structure of a table into a temporary table
without getting constraint and identity information?

currently I am trying this on a table that has an identity column:

select *
into #businessInfo
from tblBusinessInfo
where 1=0

This first statement gets me the identity column. Later, depending on the
results of other queries, I need to populate this table with non-sequential
values in the identity column and then export it. Needless to say, I can't
do inserts because the identity is being copied to the temporary table. I
also can't manually build the temporary table because I need to be able to
accomidate changing table structures.

Am I thinking about this wrong? Can this be done with a SQL 7 table
variable?

Please help!

Luke

 
 
 

Copying the structure of a table into a temporary table without constraint and identities

Post by Aaron Bertrand - MV » Fri, 04 Apr 2003 07:32:38


Quote:> currently I am trying this on a table that has an identity column:

> select *
> into #businessInfo
> from tblBusinessInfo
> where 1=0

> This first statement gets me the identity column. Later, depending on the
> results of other queries, I need to populate this table with
non-sequential
> values in the identity column and then export it. Needless to say, I can't
> do inserts because the identity is being copied to the temporary table.

Can you then do

ALTER TABLE #businessInfo DROP COLUMN identityColumnName
ALTER TABLE #businessInfo ADD identityColumnName INT

Otherwise,

CREATE TABLE #businessInfo
 (column list WITH identity column but WITHOUT identity property)

Then, INSERT #businessInfo ...

Quote:> Am I thinking about this wrong? Can this be done with a SQL 7 table
> variable?

No such thing.  Table variables were introduced with SQL 2000.

--
AB
www.aspfaq.com

 
 
 

Copying the structure of a table into a temporary table without constraint and identities

Post by Luke Jange » Fri, 04 Apr 2003 08:05:17


Aaron,

Good answer. Thanks, you saved me a lot of worrying.

Luke



Quote:> > currently I am trying this on a table that has an identity column:

> > select *
> > into #businessInfo
> > from tblBusinessInfo
> > where 1=0

> > This first statement gets me the identity column. Later, depending on
the
> > results of other queries, I need to populate this table with
> non-sequential
> > values in the identity column and then export it. Needless to say, I
can't
> > do inserts because the identity is being copied to the temporary table.

> Can you then do

> ALTER TABLE #businessInfo DROP COLUMN identityColumnName
> ALTER TABLE #businessInfo ADD identityColumnName INT

> Otherwise,

> CREATE TABLE #businessInfo
>  (column list WITH identity column but WITHOUT identity property)

> Then, INSERT #businessInfo ...

> > Am I thinking about this wrong? Can this be done with a SQL 7 table
> > variable?

> No such thing.  Table variables were introduced with SQL 2000.

> --
> AB
> www.aspfaq.com

 
 
 

1. Copying the structure of one Access table to a new Access table

Hi all,

Using VB6 sp4 I am connecting to Access 97 databases to view the contents of
a particular table.  I want to be able to move records from this table to a
different table.

Now here is the question.  I want to be able to copy the structure of the
table I am viewing to a new table with a different name.  This new table
will then hold the records I want to move.

Is there an easy way to do this using ADO 2.5?

Thank-you

Regards,

Paul

2. Newbie question - Cascading Delete with triggers

3. List structure of temporary table

4. Oracle Resources (JOBS, RESUMES, LINKS, TUNING SCRIPT)!

5. Primary key or constraints in temporary table

6. How to get the handle of SQLBase in Win95? Please!

7. Named constraints in Temporary Tables

8. PK-constraint on Temporary tables ...

9. How drop all temporary tables without reopen session?

10. Get images from table without temporary file

11. Identity locumns and temporary tables

12. can I modify table structure without downloading database?