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 |
|
henrikop
Constraint Violating Yak Guru
280 Posts |
Posted - 2007-07-02 : 09:27:50
|
| I have a table tblArticle and a table tblCondition and a table to link these to on a many to many relation : tblArticleConditiontable article has two columns: guid, code tblCondition has three columns: guid, TypeId, ValuetblArticleCondition has two columns who form the primary key: ArticleId, ConditionIdIf I import new articles I want to add a condition "Price"Can i insert records into tblCondition and tblArticleCondition without using a temporary table? And how do I do that?Henri~~~~There's no place like 127.0.0.1 |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-07-02 : 09:31:53
|
| I suppose you could set up a VIEW with an INSTEAD OF TRIGGER and insert into that.Personally I would use a Stored Procedure which took the data for tblCondition and tblArticleCondition and made an insert into both tables, all within a Transaction so that either both success, or the transaction is rolled back.Or have an "Import table" which is "flat", insert data into there, and then all a Stored Procedure that processes the data into the two, or more, tables. This method is helpful if you have flat files to import or want to provide a more straightforward method for 3rd parties to insert into. Your Insert Sproc should delete rows from the Import Table after they have been successfully processed.Kristen |
 |
|
|
rudesyle
Posting Yak Master
110 Posts |
Posted - 2007-07-02 : 09:36:41
|
quote: Originally posted by henrikop I have a table tblArticle and a table tblCondition and a table to link these to on a many to many relation : tblArticleConditiontable article has two columns: guid, code tblCondition has three columns: guid, TypeId, ValuetblArticleCondition has two columns who form the primary key: ArticleId, ConditionIdIf I import new articles I want to add a condition "Price"Can i insert records into tblCondition and tblArticleCondition without using a temporary table? And how do I do that?Henri~~~~There's no place like 127.0.0.1
If this is something that will be done more than once, then defintely a stored procedure |
 |
|
|
henrikop
Constraint Violating Yak Guru
280 Posts |
Posted - 2007-07-03 : 03:10:30
|
A stored procedure is irrelevant in the question. The crux of the problem is inserting records in two tables and linking the right records.I will look into a view with an instead of trigger, never found use for it, some time to learn something new .For the time being a used an extra column in tblCondition to link to an article. After making the link record I empty this extra column.Using a temp table would be easiest, however I choose for quick and very dirty... Thx!!Henri~~~~There's no place like 127.0.0.1 |
 |
|
|
|
|
|
|
|