protected override void BuildStartCreateTableStatement(SqlCreateTableStatement createTable) { if (createTable.StatementHeader == null && createTable.Table !.TableOptions.HasCreateIfNotExists()) { var table = createTable.Table; var isTemporary = IsTemporary(table.TableName.Name, table.TableOptions); _skipBrackets = true; StringBuilder.Append("IF (OBJECT_ID(N'"); BuildPhysicalTable(table, null); StringBuilder.AppendLine("') IS NULL)"); _skipBrackets = false; if (!isTemporary) { Indent++; AppendIndent().AppendLine("EXECUTE('"); } Indent++; } base.BuildStartCreateTableStatement(createTable); }
protected override void BuildEndCreateTableStatement(SqlCreateTableStatement createTable) { base.BuildEndCreateTableStatement(createTable); if (createTable.StatementHeader == null && createTable.Table !.TableOptions.HasCreateIfNotExists()) { if (!IsTemporary(createTable.Table.TableName.Name, createTable.Table.TableOptions)) { Indent--; AppendIndent().AppendLine("')"); } Indent--; } }
protected override void BuildStartCreateTableStatement(SqlCreateTableStatement createTable) { if (createTable.StatementHeader == null && createTable.Table !.TableOptions.HasCreateIfNotExists()) { AppendIndent().AppendLine(@"BEGIN"); Indent++; AppendIndent().AppendLine(@"DECLARE CONTINUE HANDLER FOR SQLSTATE '42710' BEGIN END;"); AppendIndent().AppendLine(@"EXECUTE IMMEDIATE '"); Indent++; } base.BuildStartCreateTableStatement(createTable); }
protected override void BuildEndCreateTableStatement(SqlCreateTableStatement createTable) { base.BuildEndCreateTableStatement(createTable); if (createTable.StatementHeader == null && createTable.Table !.TableOptions.HasCreateIfNotExists()) { Indent--; AppendIndent() .AppendLine("';"); Indent--; StringBuilder .AppendLine("END"); } }