Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Simulating multiple tables
Message
De
08/07/2009 10:44:21
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Conception bases de données
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01410856
Message ID:
01410903
Vues:
34
>>>Can you post what you tried already?
>>>
>>>To me this sounds like
>>>
>>>trigger body
>>>
>>>insert into mySecondTable select ID, some other info from Inserted
>>
>>This works - but requires a ProductFileId field in ProductFileData:
    DECLARE @rowid uniqueidentifier
>>    SET @rowid = NEWID()
>>    INSERT INTO ProductFileData
>>    (ProductFileColumnId,ProductFileRowId,ProductFileId)
>>    SELECT INSERTED.Id,@rowid,INSERTED.ProductFileId
>>    FROM INSERTED INNER JOIN ProductFileData ON ProductFileData.ProductFileId = INSERTED.ProductFileId
>>
>>UPDATE: On second thoughts - it doesn't - I need unique row IDs.....
>
>Exactly - I was going to tell that it's not going to work this way because of multiple inserts possibility.
>
>But would this work?
>
>    INSERT INTO ProductFileData
>    (ProductFileColumnId,ProductFileRowId,ProductFileId)
>    SELECT INSERTED.Id,NewID(),INSERTED.ProductFileId
>    FROM INSERTED INNER JOIN ProductFileData ON ProductFileData.ProductFileId = INSERTED.ProductFileId
>
>Or why not let ProductFileRowID field to have default NewID() and then you don't need to include it in insert?

Actually what I posted above is complete rubbish. The ProductFileRowId has to be based on existing unique values for existing rows.
Using NEWID() is completely wrong. Using a default would be worse because all the rows would have different Ids. Let me try again....
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform