Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Post deploy script in VS 2013 Database project

$
0
0
I have a couple of merge scripts that are run post deployment, one of which sets up a lookup table as per:[code="sql"] MERGE INTO [Languages] AS Target USING (VALUES ('English','eng','en') ,('French','fra','fr') ) AS Source ([LanguageName],[Iso639Code],[Locale]) ON (Target.[Iso639Code] = Source.[Iso639Code]) WHEN MATCHED THEN UPDATE SET [LanguageName] = Source.[LanguageName], [Locale] = Source.[Locale], [UserModified] = @UpdatedBy, [ModifiedDateTime] = GETDATE() WHEN NOT MATCHED BY TARGET THEN INSERT([LanguageName],[Iso639Code],[Locale],[UserCreate],[CreateDateTime]) VALUES(Source.[LanguageName],Source.[Iso639Code],Source.[Locale],@UpdatedBy,GETDATE()); GO[/code]This table has an [int] as the primary key. This script works well. So my question is I now have another script which needs to look up the primary key from this table to insert into a second table.[code="sql"] MERGE INTO [Countries] AS Target USING (VALUES ('England') ,('France') ) AS Source ([CountryName]) ON (Target.[CountryName] = Source.[CountryName]) WHEN MATCHED THEN UPDATE SET [CountryName] = Source.[CountryName], [LanguageId] = (Select LanguageID from [Languages] where [LanguageName] = Source.[LanguageName]), [Locale] = Source.[Locale], [UserModified] = @UpdatedBy, [ModifiedDateTime] = GETDATE() WHEN NOT MATCHED BY TARGET THEN INSERT([CountryName],LanguageId,[UserCreate],[CreateDateTime]) VALUES(Source.[CountryName],(Select LanguageID from [Languages] where [LanguageName] = Source.[LanguageName]),@UpdatedBy,GETDATE()); GO[/code]Is this the correct procedure to link the two tables with the post deployment scripts?

Viewing all articles
Browse latest Browse all 3145

Trending Articles