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.
| Author |
Topic |
|
interclubs
Yak Posting Veteran
63 Posts |
Posted - 2003-06-03 : 22:16:54
|
| I know this is easy, but I am an idiot and can't figure it out. I have a table:StoryID|Headline|Story(StoryID) is an identity fieldand I want to write a stored proc that will loop thru the table and insert the data into two tables like:Table1: StoryID|HeadlineTable2: StoryID|Story(where StoryID is the same StoryID from the original table)Thanks guys, I appreciate it. |
|
|
ValterBorges
Master Smack Fu Yak Hacker
1429 Posts |
Posted - 2003-06-03 : 22:30:34
|
| INSERT INTO Table1 (StoryID, Headline)SELECT StoryID, HeadlineFROM OriginalTableINSERT INTO Table2 (StoryID, Story)SELECT StoryID, StoryFROM OriginalTable |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2003-06-03 : 22:34:43
|
| No looping needed here. Just need to be able to insert the identity column into the other tables so you need to turn that feature on, well that is if StoryID is an identity column in the other two tables also.Let's call your original table Table1, and the other two tables Table2 (contains Headline column) and Table3 (contains Story column).SET IDENTITY_INSERT ON Table2INSERT INTO Table2 (StoryID, Headline)SELECT StoryID, HeadlineFROM Table1SET IDENTITY_INSERT OFF Table2SET IDENTITY_INSERT ON Table3INSERT INTO Table3 (StoryID, Story)SELECT StoryID, StoryFROM Table1SET IDENTITY_INSERT OFF Table3TaraEdited by - tduggan on 06/03/2003 22:51:00 |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2003-06-04 : 12:08:50
|
| Building a normalized database "on th fly"...interesting...How often does this need to be done? Everytime a row is inserted?Guess it'd be kinda hard to have RI..guess you could use a non identifying relationship...Brett8-) |
 |
|
|
|
|
|
|
|