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 Development (2000)
 Initializing a table with (almost) blank records

Author  Topic 

flamz
Starting Member

21 Posts

Posted - 2008-10-08 : 13:47:43
Hi,
I have 2 tables, like this:

table1
[ID],[FIELD1], [FIELD2], [...]

table2
[TABLE1_ID], [DATA1], [DATA2], [DATA3],[...]

I need to initialize the table 2 to all zeros except [TABLE1_ID] which must be equal to the ID of table1. Meaning that if I have 3 records in table1 having IDs 101,102 and 103, I would end up with this in table2:

[TABLE1_ID],[DATA1],[DATA2],[DATA3],[...]
101,0,0,0,...
102,0,0,0,...
103,0,0,0,...

I have a query setup to do this, but it's slow... any way to do this in one nice, quick query?

tx.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-08 : 13:58:41
[code]INSERT INTO Table2
SELECT ID,
0,0,0,0,..
FROM table1[/code]
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-08 : 14:00:03
Alternatively you could create default constraints on all except ID column in table2 for value to be 0 and use this

INSERT INTO Table2 (Table1_ID)
SELECT ID
FROM table1
Go to Top of Page
   

- Advertisement -