Skip to content

Please stop including SET QUOTED_IDENTIFIER OFF for external tables #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
SQLvariant opened this issue May 3, 2022 · 3 comments
Closed

Comments

@SQLvariant
Copy link

Please quit including SET QUOTED_IDENTIFIER OFF when scripting out the CREATE of an external table?

This causes an error in Synapse:
Msg 104409, Level 16, State 1, Line 9 Setting QUOTED_IDENTIFIER to 'OFF' is not supported.

@jzabroski
Copy link

jzabroski commented May 20, 2022

@SQLvariant you can add a regression test by following some of the examples:

public void ScriptMaker_Verify_CreateOrAlter_scripts_Table_as_Create()
{
ExecuteFromDbPool(TestContext.FullyQualifiedTestClassName, (db) =>
{
var table = DatabaseObjectHelpers.CreateTable(db, "table");
var scriptingPreferences = new ScriptingPreferences(db)
{
Behavior = ScriptBehavior.CreateOrAlter
};
var tableName = SmoObjectHelpers.SqlBracketQuoteString(table.Name);
var server = db.GetServerObject();
scriptingPreferences.OldOptions.EnforceScriptingPreferences = true;
var m = new ScriptMaker(server)
{
Preferences = scriptingPreferences
};
var dependencyDiscoverer = new SmoDependencyDiscoverer(server)
{
Preferences = scriptingPreferences
};
m.discoverer = dependencyDiscoverer;
scriptingPreferences.IncludeScripts.ExistenceCheck = true;
ValidateUrnScripting(db, new Urn[] {table.Urn}, new string[]
{
"SET ANSI_NULLS ON",
"SET QUOTED_IDENTIFIER ON",
$"IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].{tableName.SqlEscapeSingleQuote()}') AND type in (N'U')){Environment.NewLine}BEGIN{Environment.NewLine}CREATE TABLE [dbo].{tableName}({Environment.NewLine}\t[col_1] [int] NULL{Environment.NewLine}) ON [PRIMARY]{Environment.NewLine}END"
}, scriptingPreferences );
});
}

@shueybubbles
Copy link
Collaborator

For this case I think it makes sense to hard code the QuotedIdentifierStatus property to 1 for DW

eg

<version datawarehouse_enabled='true'>
<property name="QuotedIdentifierStatus" type="bit" cast='true' read_only_after_creation="true" mode="design">1</property>
</Version>

Today it's using an OBJECTPROPERTY for all versions:

<property name="QuotedIdentifierStatus" type="bit" cast='true' read_only_after_creation="true" mode="design">ISNULL(OBJECTPROPERTY(tbl.object_id,N'IsQuotedIdentOn'),0)</property>

@shueybubbles
Copy link
Collaborator

Well, this clarifies things a bit, from the docs:

When a table is created, the QUOTED IDENTIFIER option is always stored as ON in the table's metadata even if the option is set to OFF when the table is created.

So we can just change the default from 0 to 1 for tables when the objectproperty is null.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants