Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Simulating multiple tables
Message
De
08/07/2009 10:31:46
 
 
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:
01410898
Vues:
37
>>>>>>>Do you want to have a trigger firing when a new column is added?
>>>>>>Yes
>>>>>> In SQL Server 2005 you need to look at DDL triggers.
>>>>>>Why?
>>>>>>
>>>>>>Viv
>>>>>>
>>>>>>
>>>>>Why not? DDL triggers are supposed to fire when the structure changes - looks like your case.
>>>>No - structure doesn't change. It's just an INSERT into the ProductFileColumns table.
>>>>When that happens I need to add a record in ProductFileData for each existing row using the Id of the newly inserted column.
>>>
>>>Aha, when what seems to be a problem? Just write a simple AFTER INSERT trigger.
>>As per the original post I don't know how to do this in the most efficient way. Care to post some code?
>>Best,
>>Viv
>
>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.....
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform