Showing posts with label identifier. Show all posts
Showing posts with label identifier. Show all posts

Wednesday, March 21, 2012

Quoted Identifier ON as default

Currently my user databases, and model database, all have QUOTED IDENTIFER
set to false.
I want to help ensure that QUOTED_IDENTIFIER is set to ON under the following
conditions:
1. When a stored procedure is created (assuming the connection that is
performing the create, allows database default settings) to use the database
default settings. In other words, there is not a SET QUOTED_IDENTIFIER ON
statement when the procedure is created or altered, but instead it uses the
database default setting.
2. When a new database is created, its default setting is QUOTED IDENTIFIERS
ENABLED = TRUE.
How would one go about doing this?
Message posted via http://www.droptable.com
"cbrichards via droptable.com" <u3288@.uwe> wrote in message
news:6a6bb12d8cd92@.uwe...
> Currently my user databases, and model database, all have QUOTED IDENTIFER
> set to false.
> I want to help ensure that QUOTED_IDENTIFIER is set to ON under the
> following
> conditions:
> 1. When a stored procedure is created (assuming the connection that is
> performing the create, allows database default settings) to use the
> database
> default settings. In other words, there is not a SET QUOTED_IDENTIFIER ON
> statement when the procedure is created or altered, but instead it uses
> the
> database default setting.
> 2. When a new database is created, its default setting is QUOTED
> IDENTIFIERS
> ENABLED = TRUE.
> How would one go about doing this?
For the database you will have to monitor and complain, since creating
databases cannot be rolled back.
For stored procedures you can add a DDL Trigger in each database that will
prevent stored procedure creation or modification from a connection that
does not have the required setting. EG
CREATE TRIGGER ddl_trig_enforce_quoted_identifiers
ON database
FOR CREATE_PROCEDURE, ALTER_PROCEDURE
AS
begin
declare @.quoted_identifiers varchar(5)
set @.quoted_identifiers = EVENTDATA().value(
'(/EVENT_INSTANCE/TSQLCommand/SetOptions/@.QUOTED_IDENTIFIER)[1]',
'nvarchar(max)')
if @.quoted_identifiers <> 'ON'
begin
raiserror('You must use SET QUOTED_IDENTIFIER ON to create or alter a
procedure.',16,1)
end
--select @.quoted_identifiers quoted_identifiers
end
GO
Then
SET QUOTED_IDENTIFIER off
go
create procedure foo
as
select 1 a
Fails with
Msg 50000, Level 16, State 1, Procedure ddl_trig_enforce_quoted_identifiers,
Line 13
You must use SET QUOTED_IDENTIFIER ON to create or alter a procedure.
David

Quoted Identifier ON as default

Currently my user databases, and model database, all have QUOTED IDENTIFER
set to false.
I want to help ensure that QUOTED_IDENTIFIER is set to ON under the followin
g
conditions:
1. When a stored procedure is created (assuming the connection that is
performing the create, allows database default settings) to use the database
default settings. In other words, there is not a SET QUOTED_IDENTIFIER ON
statement when the procedure is created or altered, but instead it uses the
database default setting.
2. When a new database is created, its default setting is QUOTED IDENTIFIERS
ENABLED = TRUE.
How would one go about doing this?
Message posted via http://www.droptable.com"cbrichards via droptable.com" <u3288@.uwe> wrote in message
news:6a6bb12d8cd92@.uwe...
> Currently my user databases, and model database, all have QUOTED IDENTIFER
> set to false.
> I want to help ensure that QUOTED_IDENTIFIER is set to ON under the
> following
> conditions:
> 1. When a stored procedure is created (assuming the connection that is
> performing the create, allows database default settings) to use the
> database
> default settings. In other words, there is not a SET QUOTED_IDENTIFIER ON
> statement when the procedure is created or altered, but instead it uses
> the
> database default setting.
> 2. When a new database is created, its default setting is QUOTED
> IDENTIFIERS
> ENABLED = TRUE.
> How would one go about doing this?
For the database you will have to monitor and complain, since creating
databases cannot be rolled back.
For stored procedures you can add a DDL Trigger in each database that will
prevent stored procedure creation or modification from a connection that
does not have the required setting. EG
CREATE TRIGGER ddl_trig_enforce_quoted_identifiers
ON database
FOR CREATE_PROCEDURE, ALTER_PROCEDURE
AS
begin
declare @.quoted_identifiers varchar(5)
set @.quoted_identifiers = EVENTDATA().value(
'(/EVENT_INSTANCE/TSQLCommand/SetOptions/@.QUOTED_IDENTIFIER)[1]',
'nvarchar(max)')
if @.quoted_identifiers <> 'ON'
begin
raiserror('You must use SET QUOTED_IDENTIFIER ON to create or alter a
procedure.',16,1)
end
--select @.quoted_identifiers quoted_identifiers
end
GO
Then
SET QUOTED_IDENTIFIER off
go
create procedure foo
as
select 1 a
Fails with
Msg 50000, Level 16, State 1, Procedure ddl_trig_enforce_quoted_identifiers,
Line 13
You must use SET QUOTED_IDENTIFIER ON to create or alter a procedure.
David|||Also, the database option is largely useless as all modern APIs (and tools)
will override the
database settings.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"David Browne" <davidbaxterbrowne no potted meat@.hotmail.com> wrote in messa
ge
news:%23TX5k4kGHHA.4920@.TK2MSFTNGP05.phx.gbl...
>
> "cbrichards via droptable.com" <u3288@.uwe> wrote in message news:6a6bb12d
8cd92@.uwe...
>
> For the database you will have to monitor and complain, since creating dat
abases cannot be rolled
> back.
> For stored procedures you can add a DDL Trigger in each database that will
prevent stored
> procedure creation or modification from a connection that does not have th
e required setting. EG
> CREATE TRIGGER ddl_trig_enforce_quoted_identifiers
> ON database
> FOR CREATE_PROCEDURE, ALTER_PROCEDURE
> AS
> begin
> declare @.quoted_identifiers varchar(5)
> set @.quoted_identifiers = EVENTDATA().value(
> '(/EVENT_INSTANCE/TSQLCommand/SetOptions/@.QUOTED_IDENTIFIER)[1]',
> 'nvarchar(max)')
> if @.quoted_identifiers <> 'ON'
> begin
> raiserror('You must use SET QUOTED_IDENTIFIER ON to create or alter a p
rocedure.',16,1)
> end
> --select @.quoted_identifiers quoted_identifiers
> end
> GO
> Then
> SET QUOTED_IDENTIFIER off
> go
> create procedure foo
> as
> select 1 a
> Fails with
> Msg 50000, Level 16, State 1, Procedure ddl_trig_enforce_quoted_identifier
s, Line 13
> You must use SET QUOTED_IDENTIFIER ON to create or alter a procedure.
>
> David
>

Quoted Identifier ON as default

Currently my user databases, and model database, all have QUOTED IDENTIFER
set to false.
I want to help ensure that QUOTED_IDENTIFIER is set to ON under the following
conditions:
1. When a stored procedure is created (assuming the connection that is
performing the create, allows database default settings) to use the database
default settings. In other words, there is not a SET QUOTED_IDENTIFIER ON
statement when the procedure is created or altered, but instead it uses the
database default setting.
2. When a new database is created, its default setting is QUOTED IDENTIFIERS
ENABLED = TRUE.
How would one go about doing this?
--
Message posted via http://www.sqlmonster.com"cbrichards via SQLMonster.com" <u3288@.uwe> wrote in message
news:6a6bb12d8cd92@.uwe...
> Currently my user databases, and model database, all have QUOTED IDENTIFER
> set to false.
> I want to help ensure that QUOTED_IDENTIFIER is set to ON under the
> following
> conditions:
> 1. When a stored procedure is created (assuming the connection that is
> performing the create, allows database default settings) to use the
> database
> default settings. In other words, there is not a SET QUOTED_IDENTIFIER ON
> statement when the procedure is created or altered, but instead it uses
> the
> database default setting.
> 2. When a new database is created, its default setting is QUOTED
> IDENTIFIERS
> ENABLED = TRUE.
> How would one go about doing this?
For the database you will have to monitor and complain, since creating
databases cannot be rolled back.
For stored procedures you can add a DDL Trigger in each database that will
prevent stored procedure creation or modification from a connection that
does not have the required setting. EG
CREATE TRIGGER ddl_trig_enforce_quoted_identifiers
ON database
FOR CREATE_PROCEDURE, ALTER_PROCEDURE
AS
begin
declare @.quoted_identifiers varchar(5)
set @.quoted_identifiers = EVENTDATA().value(
'(/EVENT_INSTANCE/TSQLCommand/SetOptions/@.QUOTED_IDENTIFIER)[1]',
'nvarchar(max)')
if @.quoted_identifiers <> 'ON'
begin
raiserror('You must use SET QUOTED_IDENTIFIER ON to create or alter a
procedure.',16,1)
end
--select @.quoted_identifiers quoted_identifiers
end
GO
Then
SET QUOTED_IDENTIFIER off
go
create procedure foo
as
select 1 a
Fails with
Msg 50000, Level 16, State 1, Procedure ddl_trig_enforce_quoted_identifiers,
Line 13
You must use SET QUOTED_IDENTIFIER ON to create or alter a procedure.
David|||Also, the database option is largely useless as all modern APIs (and tools) will override the
database settings.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"David Browne" <davidbaxterbrowne no potted meat@.hotmail.com> wrote in message
news:%23TX5k4kGHHA.4920@.TK2MSFTNGP05.phx.gbl...
>
> "cbrichards via SQLMonster.com" <u3288@.uwe> wrote in message news:6a6bb12d8cd92@.uwe...
>> Currently my user databases, and model database, all have QUOTED IDENTIFER
>> set to false.
>> I want to help ensure that QUOTED_IDENTIFIER is set to ON under the following
>> conditions:
>> 1. When a stored procedure is created (assuming the connection that is
>> performing the create, allows database default settings) to use the database
>> default settings. In other words, there is not a SET QUOTED_IDENTIFIER ON
>> statement when the procedure is created or altered, but instead it uses the
>> database default setting.
>> 2. When a new database is created, its default setting is QUOTED IDENTIFIERS
>> ENABLED = TRUE.
>> How would one go about doing this?
>
> For the database you will have to monitor and complain, since creating databases cannot be rolled
> back.
> For stored procedures you can add a DDL Trigger in each database that will prevent stored
> procedure creation or modification from a connection that does not have the required setting. EG
> CREATE TRIGGER ddl_trig_enforce_quoted_identifiers
> ON database
> FOR CREATE_PROCEDURE, ALTER_PROCEDURE
> AS
> begin
> declare @.quoted_identifiers varchar(5)
> set @.quoted_identifiers = EVENTDATA().value(
> '(/EVENT_INSTANCE/TSQLCommand/SetOptions/@.QUOTED_IDENTIFIER)[1]',
> 'nvarchar(max)')
> if @.quoted_identifiers <> 'ON'
> begin
> raiserror('You must use SET QUOTED_IDENTIFIER ON to create or alter a procedure.',16,1)
> end
> --select @.quoted_identifiers quoted_identifiers
> end
> GO
> Then
> SET QUOTED_IDENTIFIER off
> go
> create procedure foo
> as
> select 1 a
> Fails with
> Msg 50000, Level 16, State 1, Procedure ddl_trig_enforce_quoted_identifiers, Line 13
> You must use SET QUOTED_IDENTIFIER ON to create or alter a procedure.
>
> David
>sql

Quoted Identifier nonsense

I Have a query that does the following:
SELECT PAT.LastName + ", " + PAT.FirstName AS FirstName FROM X
I have Quoted Identifiers turned OFF and yet this query fails because it
says that ',' is not a valid column name.
Um, unless everything has changed, the expression in " " should be treated
as a constant with quoted identifiers off, right?
Any other ideas?Are you sure you have the setting OFF? Try the following in QA:
SET QUOTED_IDENTIFIER OFF
GO
SELECT au_fname + ", " + au_lname
FROM Pubs..authors;
--
- Anith
( Please reply to newsgroups only )|||Ok,
I did that and then it worked UNTIL I closed my Query Analyzer window and
then we are back to the same behavior. I am SURE the setting is off in the
DB properties otherwise...
I am getting concerned
"Anith Sen" <anith@.bizdatasolutions.com> wrote in message
news:OUIiK4GtDHA.1224@.TK2MSFTNGP09.phx.gbl...
> Are you sure you have the setting OFF? Try the following in QA:
> SET QUOTED_IDENTIFIER OFF
> GO
> SELECT au_fname + ", " + au_lname
> FROM Pubs..authors;
> --
> - Anith
> ( Please reply to newsgroups only )
>|||It is simply a QA behaviour which you are seeing. QA sets SET
QUOTED_IDENTIFIER to ON by default and so, you have to explcitly set to OFF
to make your query work.
To behave the same way as in SQL 7.0, keep the setting to OFF. This has
little to do with the overall behaviour of the database.
--
- Anith
( Please reply to newsgroups only )|||Setting it as a database property doesn't work at all. Every time you start
a new QA session, ODBC sends its own SET commands to SQL Server which
override anything you have set at the db level. I wrote a column for SQL
Server Magazine pointing out that in most cases setting database options for
the ANSI behaviors is absolutely useless, because it always gets overridden
at the session level.
Even in YOU don't set it, the API sets it behind the scenes for you. You can
watch this happen in Profiler. :-)
For the Query Analyzer Tool, you can go to Tools|Options|Connection
Properties, and clear the box for setting Quoted Identifer. Then all new
connections in QA will have this OFF. But if you use other tools, they will
not be affected.
--
HTH
--
Kalen Delaney
SQL Server MVP
www.SolidQualityLearning.com
"A" <agarrettbNOSPAM@.hotmail.com> wrote in message
news:u8qBu9GtDHA.1680@.TK2MSFTNGP12.phx.gbl...
> Ok,
> I did that and then it worked UNTIL I closed my Query Analyzer window and
> then we are back to the same behavior. I am SURE the setting is off in
the
> DB properties otherwise...
> I am getting concerned
>
> "Anith Sen" <anith@.bizdatasolutions.com> wrote in message
> news:OUIiK4GtDHA.1224@.TK2MSFTNGP09.phx.gbl...
> > Are you sure you have the setting OFF? Try the following in QA:
> >
> > SET QUOTED_IDENTIFIER OFF
> > GO
> > SELECT au_fname + ", " + au_lname
> > FROM Pubs..authors;
> >
> > --
> > - Anith
> > ( Please reply to newsgroups only )
> >
> >
>|||In addition to the other posts:
Is there any particular reason why you want to use double quotes for string delimiters? This is
non-standard and SQL Server is moving away from this (as you have noticed).
--
Tibor Karaszi, SQL Server MVP
Archive at: http://groups.google.com/groups?oi=djq&as_ugroup=microsoft.public.sqlserver
"A" <agarrettbNOSPAM@.hotmail.com> wrote in message news:u8qBu9GtDHA.1680@.TK2MSFTNGP12.phx.gbl...
> Ok,
> I did that and then it worked UNTIL I closed my Query Analyzer window and
> then we are back to the same behavior. I am SURE the setting is off in the
> DB properties otherwise...
> I am getting concerned
>
> "Anith Sen" <anith@.bizdatasolutions.com> wrote in message
> news:OUIiK4GtDHA.1224@.TK2MSFTNGP09.phx.gbl...
> > Are you sure you have the setting OFF? Try the following in QA:
> >
> > SET QUOTED_IDENTIFIER OFF
> > GO
> > SELECT au_fname + ", " + au_lname
> > FROM Pubs..authors;
> >
> > --
> > - Anith
> > ( Please reply to newsgroups only )
> >
> >
>

Quoted identifier

On the Options tab in database properties, there is an option of Use quoted
identifiers,
does anyone knows the option of this for what purpose and any example ?
Connection settings, such as quoted identifiers, can be set at the
connection, database or server level:
1) connection: SET QUOTED_IDENTIFIER ON
2) database: Enterprise Manager database properties or
ALTER DATABASE MyDatabase
SET QUOTED_IDENTIFIER ON
3) server: EXEC sp_configure 'user options', 256
Settings at the connection level override database and server settings.
Setting at the database level override the server specification.
When quoted identifiers is on (the ANSI standard), double quotes can be used
to enclose identifiers and single quotes are used for literal strings. OLE
DB and ODBC APIs set QUOTED_IDENTIFIER ON when connecting.
See the Books Online for details.
Hope this helps.
Dan Guzman
SQL Server MVP
"Alan" <NOSPAMalan_pltse@.yahoo.com.au> wrote in message
news:usKgtRpqEHA.3980@.TK2MSFTNGP12.phx.gbl...
> On the Options tab in database properties, there is an option of Use
> quoted
> identifiers,
> does anyone knows the option of this for what purpose and any example ?
>

Tuesday, March 20, 2012

Quoted identifier

On the Options tab in database properties, there is an option of Use quoted
identifiers,
does anyone knows the option of this for what purpose and any example ?Connection settings, such as quoted identifiers, can be set at the
connection, database or server level:
1) connection: SET QUOTED_IDENTIFIER ON
2) database: Enterprise Manager database properties or
ALTER DATABASE MyDatabase
SET QUOTED_IDENTIFIER ON
3) server: EXEC sp_configure 'user options', 256
Settings at the connection level override database and server settings.
Setting at the database level override the server specification.
When quoted identifiers is on (the ANSI standard), double quotes can be used
to enclose identifiers and single quotes are used for literal strings. OLE
DB and ODBC APIs set QUOTED_IDENTIFIER ON when connecting.
See the Books Online for details.
--
Hope this helps.
Dan Guzman
SQL Server MVP
"Alan" <NOSPAMalan_pltse@.yahoo.com.au> wrote in message
news:usKgtRpqEHA.3980@.TK2MSFTNGP12.phx.gbl...
> On the Options tab in database properties, there is an option of Use
> quoted
> identifiers,
> does anyone knows the option of this for what purpose and any example ?
>