Skip to content

Commit d4c1eaf

Browse files
authored
Use OBJECT_ID to check for table. Specify Schema when checking. Add GO statements. (#14)
1 parent 06b0bc1 commit d4c1eaf

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/GetSqlServerVersionInfo/Program.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ private static string BuildSqlScript(List<SqlServerBuild> builds)
194194
{
195195
var sqlScript = new StringBuilder();
196196
sqlScript.AppendLine(@"
197-
IF NOT EXISTS (SELECT NULL FROM sys.tables WHERE [name] = 'SqlServerVersions')
197+
IF (OBJECT_ID('dbo.SqlServerVersions') IS NULL)
198198
BEGIN
199199
200200
CREATE TABLE dbo.SqlServerVersions
@@ -218,6 +218,7 @@ ReleaseDate ASC
218218
);
219219
220220
END;
221+
GO
221222
222223
DELETE dbo.SqlServerVersions;"
223224
);
@@ -233,7 +234,9 @@ INSERT INTO dbo.SqlServerVersions
233234
}
234235
// Remove the trailing comma
235236
sqlScript.Remove(sqlScript.Length - 1, 1);
236-
sqlScript.Append(';');
237+
sqlScript.Append(@"
238+
;
239+
GO");
237240

238241
return sqlScript.ToString();
239242
}

0 commit comments

Comments
 (0)