Click here to Skip to main content
15,885,985 members
Home / Discussions / Database
   

Database

 
AnswerRe: Error in Restoring SQL Server Backup of v 2012 to v 2008 Pin
Victor Nijegorodov1-Jun-18 20:46
Victor Nijegorodov1-Jun-18 20:46 
AnswerRe: Error in Restoring SQL Server Backup of v 2012 to v 2008 Pin
Eddy Vluggen2-Jun-18 0:21
professionalEddy Vluggen2-Jun-18 0:21 
GeneralRe: Error in Restoring SQL Server Backup of v 2012 to v 2008 Pin
indian1434-Jun-18 6:10
indian1434-Jun-18 6:10 
GeneralRe: Error in Restoring SQL Server Backup of v 2012 to v 2008 Pin
Eddy Vluggen4-Jun-18 7:08
professionalEddy Vluggen4-Jun-18 7:08 
QuestionA Control flow Task is appearing in the SSIS Packages xml even after disabling and the deleting it. Pin
indian14331-May-18 13:34
indian14331-May-18 13:34 
QuestionThe following Query is taking too long to execute Pin
indian14330-May-18 13:33
indian14330-May-18 13:33 
SuggestionRe: The following Query is taking too long to execute Pin
CHill6031-May-18 2:53
mveCHill6031-May-18 2:53 
GeneralRe: The following Query is taking too long to execute Pin
indian14331-May-18 13:26
indian14331-May-18 13:26 
GeneralRe: The following Query is taking too long to execute Pin
Eddy Vluggen1-Jun-18 0:10
professionalEddy Vluggen1-Jun-18 0:10 
QuestionGraph Database vs Dimensional Pin
DADom24-May-18 21:32
DADom24-May-18 21:32 
AnswerRe: Graph Database vs Dimensional Pin
Eddy Vluggen26-May-18 2:45
professionalEddy Vluggen26-May-18 2:45 
GeneralRe: Graph Database vs Dimensional Pin
John 1356415428-Jun-18 9:07
John 1356415428-Jun-18 9:07 
GeneralRe: Graph Database vs Dimensional Pin
Eddy Vluggen28-Jun-18 9:19
professionalEddy Vluggen28-Jun-18 9:19 
QuestionHow to create a insert trigger on just one table? Pin
Member23621-May-18 23:02
Member23621-May-18 23:02 
QuestionRe: How to create a insert trigger on just one table? Pin
CHill6022-May-18 1:34
mveCHill6022-May-18 1:34 
AnswerRe: How to create a insert trigger on just one table? Pin
Richard Deeming22-May-18 2:30
mveRichard Deeming22-May-18 2:30 
CREATE TRIGGER (Transact-SQL) | Microsoft Docs[^]
SQL
CREATE TRIGGER YourTriggerName
ON YourTableName
AFTER insert, update
As
BEGIN
    SET NOCOUNT ON;
    
    If UPDATE(FK)
    BEGIN
        UPDATE
            T
        SET
            RedundantDuplicateColumn = T2.Name
        FROM
            YourTable As T
            INNER JOIN inserted As I
            ON I.PK = T.PK
            LEFT JOIN YourOtherTable As T2
            ON T2.PK = T.FK
        ;
    END;
END

Replace the dummy table and column names with the real table and column names.

Remember that triggers will fire once per batch, not once per row. There could be multiple rows in the inserted table.

But as CHill60 said, duplicating the product name in both tables seems like a bad design. If you have the ID of the product, you can simply join to the product table to get the name on demand.



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

AnswerRe: How to create a insert trigger on just one table? Pin
Mycroft Holmes22-May-18 14:09
professionalMycroft Holmes22-May-18 14:09 
GeneralRe: How to create a insert trigger on just one table? Pin
CHill6022-May-18 22:56
mveCHill6022-May-18 22:56 
GeneralRe: How to create a insert trigger on just one table? Pin
Mycroft Holmes23-May-18 13:20
professionalMycroft Holmes23-May-18 13:20 
GeneralRe: How to create a insert trigger on just one table? Pin
Member23622-May-18 23:04
Member23622-May-18 23:04 
GeneralRe: How to create a insert trigger on just one table? Pin
Mycroft Holmes23-May-18 13:23
professionalMycroft Holmes23-May-18 13:23 
QuestionFOR XML PATH is not creating Child elements if they are coming with null values Pin
indian14316-May-18 12:39
indian14316-May-18 12:39 
AnswerRe: FOR XML PATH is not creating Child elements if they are coming with null values Pin
CHill6022-May-18 1:32
mveCHill6022-May-18 1:32 
QuestionEquivalent of the following query without FOR XML PATH Pin
indian14314-May-18 12:03
indian14314-May-18 12:03 
SuggestionRe: Equivalent of the following query without FOR XML PATH Pin
CHill6015-May-18 0:11
mveCHill6015-May-18 0:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.