Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 Create a copy of a table without null property

Author  Topic 

rubs_65
Posting Yak Master

144 Posts

Posted - 2005-01-28 : 15:00:32
Hi,

We have to dynamically create a table in temp database based on other database and we are using:
select * into tempdb..table1 from table1 where 0=1
This works fine but it also copy the null or not null property and we want all columns to be null in new table. we are currentlt create table like this and then alter all columns to be null so we are looking if there is any better way to create tables with structure without null/not null property?

Thanks
--rubs

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-01-28 : 15:28:10
The best way would be to not use select * into. Just use CREATE TABLE to create your tables that way you can define how it should look.

Tara
Go to Top of Page

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2005-01-28 : 20:38:43
And, never create tables, other than #temp tables in tempdb. That's just asking for trouble.

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

Hyukevain
Yak Posting Veteran

66 Posts

Posted - 2005-01-29 : 10:56:00
Just like tara said, create new table in your temp DB, to dynamically retrieve column name, type and other properties, just create a script to retrieve it from syscolumns table.
Go to Top of Page
   

- Advertisement -