Sql Mass Insert Based Off Of Data Pulled From Another Table
I don't really know if I worded it correctly, but I'll try to explain what I want. Table 1 - X id | name | blah Table 2 - Y id | Xid | configKey | ConfigVal What I want to do is,
Solution 1:
To use fixed values 'doSomething' and 'true' for all inserted records:
insertinto table2 (Xid, configKey, ConfigVal)
select id, 'doSomething', 'true'from table1
Solution 2:
Use Select Into that link was SQL Server syntax, the syntax will vary from server to server, but the format is usually pretty close.
SQL Server
select id as Xid, valueas name, 'other value'as blah INTO TABLE1 from TABLE2
My SQL
INSERTINTO table1 (id, name,other_value)
SELECT xid, value, 'another value'as other_value from TABLE2
Here is a SQL Tutorial walking you through the process.
Solution 3:
I think this might work
Insertinto table2(xid, value)
select id, name from table1.
But you must have the Id column in table2 as an identity or must give it a default value. (This is only for sql server, though.)
Post a Comment for "Sql Mass Insert Based Off Of Data Pulled From Another Table"