显示标签为“nulls”的博文。显示所有博文
显示标签为“nulls”的博文。显示所有博文

2012年3月11日星期日

Any suggestions?

I have a database which contains more than 20000 stored procedures
which were created with
ansi nulls off. This i found out using the query
SELECT name,AnsiNullsOn FROM
(
SELECT name, OBJECTPROPERTY(id, 'ExecIsAnsiNullsOn') AS AnsiNullsOn
FROM sysobjects WHERE type = 'P' ) A WHERE AnsiNullsOn=0

Is there any way that i can set this property to 1 for all the stored
procedures i have??

I know the alternate method is to drop the procedure and execute the
scripts again with AnsiNullsOn = 1.

Is there any other simple ways?? It will be very helpful for me..I believe this will do the job, though I suggest some small-scale
tests first.

1) Script out all the procs as CREATEs, but do not include the DROP
option.

2) Edit the script.

- Change CREATE PROC to ALTER PROC for all procedures.

- Change all the SET ANSI_NULLS ( and possibly the SET
QUOTED_IDENTIFIER) commands as you want them.

3) Run the script.

Roy Harvey
Beacon Falls, CT

On 21 Nov 2006 14:17:38 -0800, "balaji" <mailbalajijagan@.gmail.com>
wrote:

Quote:

Originally Posted by

>I have a database which contains more than 20000 stored procedures
>which were created with
>ansi nulls off. This i found out using the query
>SELECT name,AnsiNullsOn FROM
>(
>SELECT name, OBJECTPROPERTY(id, 'ExecIsAnsiNullsOn') AS AnsiNullsOn
>FROM sysobjects WHERE type = 'P' ) A WHERE AnsiNullsOn=0
>
>Is there any way that i can set this property to 1 for all the stored
>procedures i have??
>
>I know the alternate method is to drop the procedure and execute the
>scripts again with AnsiNullsOn = 1.
>
>Is there any other simple ways?? It will be very helpful for me..

|||balaji wrote:

Quote:

Originally Posted by

I have a database which contains more than 20000 stored procedures
which were created with
ansi nulls off. This i found out using the query
SELECT name,AnsiNullsOn FROM
(
SELECT name, OBJECTPROPERTY(id, 'ExecIsAnsiNullsOn') AS AnsiNullsOn
FROM sysobjects WHERE type = 'P' ) A WHERE AnsiNullsOn=0
>
Is there any way that i can set this property to 1 for all the stored
procedures i have??
>
I know the alternate method is to drop the procedure and execute the
scripts again with AnsiNullsOn = 1.
>
Is there any other simple ways?? It will be very helpful for me..


Just to state the obvious. Since there are potential behaviour changes
associated with changing the setting it seems like the bigger task
could be testing the procs rather than making the change.

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/...US,SQL.90).aspx
--

2012年2月9日星期四

ANSI Nulls SQL Server Setting

Should I be using the SQL Server 2000 ANSI warnings, ANSI padding, ANSI null
s
since I'm using the ANSI-92 joins in my T-SQL statements?
What effect will this have on database performance with this disable?
What reason should you have that SQL Server ANSI warnings, ANSI padding,
ANSI nulls are turn off?
Please help me with these answer?
Thank You,ANSI_NULLS, ANSI_PADDING and ANSI_WARNINGS are not needed to use ANSI-92
joins.
The most important of these to consider in your queries is ANSI_NULLS, which
defines the behavior when comparing null values. But this is important even
if you are using ANSI-92 joins or not.
See 'Setting Database Options' on SQL Server 2000 BOL for more information.
Ben Nevarez
"Joe K." <Joe K.@.discussions.microsoft.com> wrote in message
news:D9C612A2-4B76-4A13-A226-D85BDC2C1422@.microsoft.com...
> Should I be using the SQL Server 2000 ANSI warnings, ANSI padding, ANSI
> nulls
> since I'm using the ANSI-92 joins in my T-SQL statements?
> What effect will this have on database performance with this disable?
> What reason should you have that SQL Server ANSI warnings, ANSI padding,
> ANSI nulls are turn off?
> Please help me with these answer?
> Thank You,

ANSI Nulls SQL Server Setting

Should I be using the SQL Server 2000 ANSI warnings, ANSI padding, ANSI nulls
since I'm using the ANSI-92 joins in my T-SQL statements?
What effect will this have on database performance with this disable?
What reason should you have that SQL Server ANSI warnings, ANSI padding,
ANSI nulls are turn off?
Please help me with these answer?
Thank You,
ANSI_NULLS, ANSI_PADDING and ANSI_WARNINGS are not needed to use ANSI-92
joins.
The most important of these to consider in your queries is ANSI_NULLS, which
defines the behavior when comparing null values. But this is important even
if you are using ANSI-92 joins or not.
See 'Setting Database Options' on SQL Server 2000 BOL for more information.
Ben Nevarez
"Joe K." <Joe K.@.discussions.microsoft.com> wrote in message
news:D9C612A2-4B76-4A13-A226-D85BDC2C1422@.microsoft.com...
> Should I be using the SQL Server 2000 ANSI warnings, ANSI padding, ANSI
> nulls
> since I'm using the ANSI-92 joins in my T-SQL statements?
> What effect will this have on database performance with this disable?
> What reason should you have that SQL Server ANSI warnings, ANSI padding,
> ANSI nulls are turn off?
> Please help me with these answer?
> Thank You,

ANSI Nulls SQL Server Setting

Should I be using the SQL Server 2000 ANSI warnings, ANSI padding, ANSI nulls
since I'm using the ANSI-92 joins in my T-SQL statements?
What effect will this have on database performance with this disable?
What reason should you have that SQL Server ANSI warnings, ANSI padding,
ANSI nulls are turn off?
Please help me with these answer?
Thank You,ANSI_NULLS, ANSI_PADDING and ANSI_WARNINGS are not needed to use ANSI-92
joins.
The most important of these to consider in your queries is ANSI_NULLS, which
defines the behavior when comparing null values. But this is important even
if you are using ANSI-92 joins or not.
See 'Setting Database Options' on SQL Server 2000 BOL for more information.
Ben Nevarez
"Joe K." <Joe K.@.discussions.microsoft.com> wrote in message
news:D9C612A2-4B76-4A13-A226-D85BDC2C1422@.microsoft.com...
> Should I be using the SQL Server 2000 ANSI warnings, ANSI padding, ANSI
> nulls
> since I'm using the ANSI-92 joins in my T-SQL statements?
> What effect will this have on database performance with this disable?
> What reason should you have that SQL Server ANSI warnings, ANSI padding,
> ANSI nulls are turn off?
> Please help me with these answer?
> Thank You,

ANSI NULLS setting in 6.5

How can I find the current ANSI_NULLS setting in 6.5?
thanksThere no such setting in 6.5 at the server level. This is something you set
in the client app, using the SET command. (In fact, the setting at the
database level in 7.0 and 2000 is mostly useless as the client will override
anyhow, and some API's and tools will set this regardless whether the
developer want to or not.)
--
Tibor Karaszi, SQL Server MVP
Archive at:
http://groups.google.com/groups?oi=djq&as_ugroup=microsoft.public.sqlserver
"peter feakins" <anonymous@.discussions.microsoft.com> wrote in message
news:92E1AC2B-3162-43AF-A04B-71CD6533CB37@.microsoft.com...
> How can I find the current ANSI_NULLS setting in 6.5?
> thanks

ANSI NULLs set at table level?

SQL 2000:
Ack! I thought my database had ANSI NULLS set to On. I find that it
doesn't. I always use IS NULL to check for the existence of nulls,
rather than using = NULL, so this setting might not matter much.
I see there is a database-wide setting for ANSI NULLS. Also, there
appears to be a setting per each table. I think.
If I modify some tables and ask to see the change script, Enterprise
Manager tells me that the table was created with ANSI NULLS set to Off,
and it will be re-created with ANSI NULLS set to ON.
For other tables, I don't get this warning.
-- Is the ANSI NULLS setting saved per table (or view)? If so, how can
I check this setting per table and change it?
Lots of the info in BOL uses the phrase "When SET ANSI_NULLS is ON," as
in the topic ANSI Comparison Options which says "When SET ANSI_NULLS is
ON, all comparisons against a null value evaluate to UNKNOWN." It
doesn't say whether this means the database-wide setting or the table
setting (assuming there is one.)
What if the database is set to ANSI NULLS ON and you're comparing two
tables, one of which was created with ANSI NULLS ON and one was created
with ANSI NULLS OFF? Or what if the database option is set one way, and
TableA is set another way, and you select from a field in that table
using WHERE FieldA = Null? Which ANSI NULLS setting is used? Where is
this *documented*?
I also see that BOL says "For stored procedures, SQL Server uses the SET
ANSI_NULLS setting value from the initial creation time of the stored
procedure." but it doesn't say anything about tables or views.
I thought I knew all about nulls, but now I'm about how and
where SQL server keeps track of the ANSI NULLS setting.
-- Related question: If I right-click a view or a proc in Enterprise
Manager, select Copy, then switch to Notepad and select Edit/Paste, I
get the view definition wrapped in SET QUOTED_IDENTIFIER (ON/OFF) and
SET ANSI_NULLS (ON/OFF) statements. The settings are different for
different views and procs. I don't think the database settings were
different when I created these views and procs, 'cause I'm not ever
switching the database-wide settings for these. What's up with that?
-- How can I get everything set to ANSI NULLS ON?
Thanks for any enlightenment.
David WalkerThere's no table level setting for ANSI_NULLS. As for stored procedures, the
y inherit the setting
from create time. You can check current setting using the OBJECTPROPERTY fun
ction. Be aware that the
database level setting is essentially useless and a connection level setting
overrides the database
level setting. And most modern API's will issue a connection level ANSI_NULL
S ON whether you like it
or not. A client app, can of course have some config file where you specify
the connection level
setting. QA is such an app.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"DWalker" <none@.none.com> wrote in message news:%23medfw0TFHA.4056@.TK2MSFTNGP15.phx.gbl...[
color=darkred]
> SQL 2000:
> Ack! I thought my database had ANSI NULLS set to On. I find that it
> doesn't. I always use IS NULL to check for the existence of nulls,
> rather than using = NULL, so this setting might not matter much.
> I see there is a database-wide setting for ANSI NULLS. Also, there
> appears to be a setting per each table. I think.
> If I modify some tables and ask to see the change script, Enterprise
> Manager tells me that the table was created with ANSI NULLS set to Off,
> and it will be re-created with ANSI NULLS set to ON.
> For other tables, I don't get this warning.
> -- Is the ANSI NULLS setting saved per table (or view)? If so, how can
> I check this setting per table and change it?
> Lots of the info in BOL uses the phrase "When SET ANSI_NULLS is ON," as
> in the topic ANSI Comparison Options which says "When SET ANSI_NULLS is
> ON, all comparisons against a null value evaluate to UNKNOWN." It
> doesn't say whether this means the database-wide setting or the table
> setting (assuming there is one.)
> What if the database is set to ANSI NULLS ON and you're comparing two
> tables, one of which was created with ANSI NULLS ON and one was created
> with ANSI NULLS OFF? Or what if the database option is set one way, and
> TableA is set another way, and you select from a field in that table
> using WHERE FieldA = Null? Which ANSI NULLS setting is used? Where is
> this *documented*?
> I also see that BOL says "For stored procedures, SQL Server uses the SET
> ANSI_NULLS setting value from the initial creation time of the stored
> procedure." but it doesn't say anything about tables or views.
> I thought I knew all about nulls, but now I'm about how and
> where SQL server keeps track of the ANSI NULLS setting.
> -- Related question: If I right-click a view or a proc in Enterprise
> Manager, select Copy, then switch to Notepad and select Edit/Paste, I
> get the view definition wrapped in SET QUOTED_IDENTIFIER (ON/OFF) and
> SET ANSI_NULLS (ON/OFF) statements. The settings are different for
> different views and procs. I don't think the database settings were
> different when I created these views and procs, 'cause I'm not ever
> switching the database-wide settings for these. What's up with that?
> -- How can I get everything set to ANSI NULLS ON?
> Thanks for any enlightenment.
> David Walker[/color]|||"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote
in news:uXjxbE1TFHA.1404@.TK2MSFTNGP09.phx.gbl:

> There's no table level setting for ANSI_NULLS. As for stored
> procedures, they inherit the setting from create time. You can check
> current setting using the OBJECTPROPERTY function. Be aware that the
> database level setting is essentially useless and a connection level
> setting overrides the database level setting. And most modern API's
> will issue a connection level ANSI_NULLS ON whether you like it or
> not. A client app, can of course have some config file where you
> specify the connection level setting. QA is such an app.
>
OK, knowing that the database level setting is essentially useless and the
connection level setting is important, is valuable information to me. Does
Enterprise Manager also use a connection to the database, which means that
there's really no way to "get" to the database without using a connection
of some sort anyway? So the database level setting would be 100%
completely useless since everyone who uses the database has to connect to
it. Strange.
My database has ANSI_NULLS set OFF. If I go into *certain* tables in
Enterprise Manager (EM), and ask to Design the table, and move (reposition)
an existing field to come before another existing field, then click on the
"Save Change Script" icon, I get this message:
"- Warning: The table was created with ANSI_NULLS 'off' and will be re-
created with ANSI_NULLS 'on'."
In this scenario, EM creates a big script that makes a temp table with the
fields in the new requested order, then copies the data, then deletes the
old table, then renames the temp one.
BUT, this warning doesn't occur if I do the same thing to *other* tables,
it just occurs if I do this procedure on the tables that were originally
created inside a stored proc.
So it LOOKS like SQL knows that ANSI_NULLS were on or off when each *table*
was created. If that's not the case, can you please explain why I get this
message when I move fields around in some tables but not others. (I'm not
really trying to move fields around in a table, I just know that this is
one way to get EM to make a script that recreates the table. And it gives
me the warning on some tables and not on others.)
Thanks.
David Walker|||> Does
> Enterprise Manager also use a connection to the database, which means that
> there's really no way to "get" to the database without using a connection
> of some sort anyway?
Correct. EM uses ODBC.

> So the database level setting would be 100%
> completely useless since everyone who uses the database has to connect to
> it.
Well, not all API's will set this setting automaticallue for you. The stone-
age DbLibrary does not.
So the database level settings can be important for for DbLibrary applicatio
ns. Here's a quote from
Books Online:
"The SQL Server ODBC driver and Microsoft OLE DB Provider for SQL Server aut
omatically set
ANSI_NULLS to ON when connecting. This setting can be configured in ODBC dat
a sources, in ODBC
connection attributes, or in OLE DB connection properties that are set in th
e application before
connecting to SQL Server. SET ANSI_NULLS defaults to OFF for connections fro
m DB-Library
applications."
I have not tried ADO.NET...
As for EM stating the message about ANSI NULLs for the table, that surpised
me. Yes, I can reproduce
it. Turns out this can be relevant for expressions for computed columns and
constraints. Read about
it in BOL, OBJECTPROPERTY, the 'IsAnsiNullsOn' option. You can check ANSI_NU
LLS setting with below:
select objectproperty(id, 'IsAnsiNullsOn'), name
from sysobjects
where type = 'u'
order by name
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"DWalker" <none@.none.com> wrote in message news:eUQv2p1TFHA.580@.TK2MSFTNGP15.phx.gbl...[col
or=darkred]
> "Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote
> in news:uXjxbE1TFHA.1404@.TK2MSFTNGP09.phx.gbl:
>
> OK, knowing that the database level setting is essentially useless and the
> connection level setting is important, is valuable information to me. Doe
s
> Enterprise Manager also use a connection to the database, which means that
> there's really no way to "get" to the database without using a connection
> of some sort anyway? So the database level setting would be 100%
> completely useless since everyone who uses the database has to connect to
> it. Strange.
> My database has ANSI_NULLS set OFF. If I go into *certain* tables in
> Enterprise Manager (EM), and ask to Design the table, and move (reposition
)
> an existing field to come before another existing field, then click on the
> "Save Change Script" icon, I get this message:
> "- Warning: The table was created with ANSI_NULLS 'off' and will be re-
> created with ANSI_NULLS 'on'."
> In this scenario, EM creates a big script that makes a temp table with the
> fields in the new requested order, then copies the data, then deletes the
> old table, then renames the temp one.
> BUT, this warning doesn't occur if I do the same thing to *other* tables,
> it just occurs if I do this procedure on the tables that were originally
> created inside a stored proc.
> So it LOOKS like SQL knows that ANSI_NULLS were on or off when each *table
*
> was created. If that's not the case, can you please explain why I get thi
s
> message when I move fields around in some tables but not others. (I'm not
> really trying to move fields around in a table, I just know that this is
> one way to get EM to make a script that recreates the table. And it gives
> me the warning on some tables and not on others.)
> Thanks.
>
> David Walker
>[/color]|||Thanks. See below.
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote
in news:#CHBHW7TFHA.2556@.TK2MSFTNGP12.phx.gbl:

> Correct. EM uses ODBC.
>
> Well, not all API's will set this setting automaticallue for you. The
> stone-age DbLibrary does not. So the database level settings can be
> important for for DbLibrary applications. Here's a quote from Books
> Online:
[...]
I see, not every library sets ANSI NULLS. But we have to assume that we
don't know how ANSI NULLS are set when we run a view that's stored in
the database, because it depends on how we're connecting. So we can't
use the semantics that ANSI NULLS OFF would provide. Not that I would
want to anyway.

> As for EM stating the message about ANSI NULLs for the table, that
> surpised me. Yes, I can reproduce it. Turns out this can be relevant
> for expressions for computed columns and constraints. Read about it in
> BOL, OBJECTPROPERTY, the 'IsAnsiNullsOn' option. You can check
> ANSI_NULLS setting with below:
> select objectproperty(id, 'IsAnsiNullsOn'), name
> from sysobjects
> where type = 'u'
> order by name
>
I'm glad I was able to surprise you. It sure surprised me to see that
message. Thanks for the pointer to that piece of BOL (it says that
IsAnsiNullsOn applies to: Function, Procedure, Table, Trigger, View).
The other parts of BOL (SET ANSI NULLS) sure don't tell you that it can
be saved at the table level.
Thanks so much for the info, I appreciate it. Good thing I'm not the
only one surprised by this table setting.
David|||Tibor:
BOL says "For stored procedures, SQL Server uses the SET ANSI_NULLS setting
value from the initial creation time of the stored procedure."
I made a test database, and I can't create a stored proc from Enterprise
Manager that has ANSI NULLS set to On! No matter what I do. The database
default setting doesn't seem to control it.
David Walker|||Skip EM for these things. Really. QA is a much better tool for writing datab
ase objects, and you're
not left out to some behavior in EM. Control!
Seems like EM does it this way (overrides the connection setting) and we don
't have control over
this...
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"DWalker" <none@.none.com> wrote in message news:%23GaE5nAUFHA.2304@.tk2msftngp13.phx.gbl...[
color=darkred]
> Tibor:
> BOL says "For stored procedures, SQL Server uses the SET ANSI_NULLS settin
g
> value from the initial creation time of the stored procedure."
> I made a test database, and I can't create a stored proc from Enterprise
> Manager that has ANSI NULLS set to On! No matter what I do. The database
> default setting doesn't seem to control it.
> David Walker
>
>[/color]|||I agree with Tobor, EM shouldnt be your power tool for control over the
database. If you know what to do in commandline or QA you will be able to
reproduce it even you got a "naked" MSDE without any (richful) GUI.
The creating or altering of a stored procedure is also a know issue to me,
it roubled me some time ago while creating queries against a herterogenous
datasource. After ALtering the Proc in the Enterprse Manager it didnt work
saying something that the ANSI NULL value wasnt set properly. With QA this
didnt happen at all.
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--
"DWalker" <none@.none.com> schrieb im Newsbeitrag
news:%23GaE5nAUFHA.2304@.tk2msftngp13.phx.gbl...
> Tibor:
> BOL says "For stored procedures, SQL Server uses the SET ANSI_NULLS
> setting
> value from the initial creation time of the stored procedure."
> I made a test database, and I can't create a stored proc from Enterprise
> Manager that has ANSI NULLS set to On! No matter what I do. The database
> default setting doesn't seem to control it.
> David Walker
>
>|||"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote
in news:eh3tgJBUFHA.2128@.TK2MSFTNGP15.phx.gbl:

> Skip EM for these things. Really. QA is a much better tool for writing
> database objects, and you're not left out to some behavior in EM.
> Control! Seems like EM does it this way (overrides the connection
> setting) and we don't have control over this...
>
OK, thanks.
David|||"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote
in news:eh3tgJBUFHA.2128@.TK2MSFTNGP15.phx.gbl:

> Skip EM for these things. Really. QA is a much better tool for writing
> database objects, and you're not left out to some behavior in EM.
> Control! Seems like EM does it this way (overrides the connection
> setting) and we don't have control over this...
>
... Except EM is sometimes easier to create views, especially with 3 or
4 joins, although I always check the generated SQL to make sure it's
right.
But it's interesting that EM won't let you create a proc with ANSI NULLS
ON. Ugh.
David

ANSI NULLS performance impact

Could someone explain why having the ANSI NULLS database option off causes
the following piece of SQL to run substantially slower. When the option is
on, in my applications ODBC settings, the query will return in less than a
second; however if the option is off then the query will take 28 seconds to
execute.
The execution plans are identical in both cases.
The application I am running is connecting via ODBC to SQL Server2000
database.
I was interested as to why this option had such a big impact on performance
- could someone explain why?
SELECT
instrument.instrument_id,
instrument.name
FROM
instrument
WHERE
(instrument.instrument_id IN ('4056719', '4072168', '4072919' .... { about
700 items in this list} ... ))
AND ((instrument.instrument_subtype_customer in ('FB', 'OB', 'SB', 'CO',
...{more items } ... 'SZ', 'WZ', 'PO', 'FS'))
and ((instrument.exchange_customer in ('EA1', 'EB1', 'LF1', 'FC1',
'EC1',...{more items } ... 'NA1', 'NAL', 'NAI')))
and not ((instrument.instrument_subtype_customer = 'DC')))
Execution plan
|--Bookmark Lookup(BOOKMARK:([Bmk1000]),
OBJECT:([PROD_GART_S40M0T0ODB].[dbo].[instrument]))
|--Hash Match(Inner Join, HASH:([Bmk1000])=([Bmk1000]),
RESIDUAL:([Bmk1000]=[Bmk1000]))
|--Hash Match(Inner Join, HASH:([Bmk1000])=([Bmk1000]),
RESIDUAL:([Bmk1000]=[Bmk1000]))
| |--Index
S(OBJECT:([PROD_GART_S40M0T0ODB].[dbo].[instrument].[pk_instrument_instrument_id]),
SEEK:([instrument].[instrument_id] >= '4000998' AND
[instrument].[instrument_id] <= '4000998' OR [instrument].[instrument_id] >=
'4002121' AND
| |--Index
S(OBJECT:([PROD_GART_S40M0T0ODB].[dbo].[instrument].[idx_instrument_exchange_customer]),
SEEK:([instrument].[exchange_customer] >= 'EA1' AND
[instrument].[exchange_customer] <= 'EA1' OR [instrument].[exchange_customer]
>= 'EB1'
|--Index
S(OBJECT:([PROD_GART_S40M0T0ODB].[dbo].[instrument].[idx_instrument_subtype_customer]),
SEEK:([instrument].[instrument_subtype_customer] >= 'CO' AND
[instrument].[instrument_subtype_customer] <= 'CO' OR
[instrument].[instrument_subtWeird stuff can happen when setting ansi_nulls to off.
A NULL Puzzle
http://groups-beta.google.com/group...aca91a7912bdc76
AMB
"dave" wrote:

> Could someone explain why having the ANSI NULLS database option off causes
> the following piece of SQL to run substantially slower. When the option is
> on, in my applications ODBC settings, the query will return in less than a
> second; however if the option is off then the query will take 28 seconds t
o
> execute.
> The execution plans are identical in both cases.
> The application I am running is connecting via ODBC to SQL Server2000
> database.
> I was interested as to why this option had such a big impact on performanc
e
> - could someone explain why?
>
> SELECT
> instrument.instrument_id,
> instrument.name
> FROM
> instrument
> WHERE
> (instrument.instrument_id IN ('4056719', '4072168', '4072919' .... { abo
ut
> 700 items in this list} ... ))
> AND ((instrument.instrument_subtype_customer in ('FB', 'OB', 'SB', 'CO',
> ...{more items } ... 'SZ', 'WZ', 'PO', 'FS'))
> and ((instrument.exchange_customer in ('EA1', 'EB1', 'LF1', 'FC1',
> 'EC1',...{more items } ... 'NA1', 'NAL', 'NAI')))
> and not ((instrument.instrument_subtype_customer = 'DC')))
>
> Execution plan
> |--Bookmark Lookup(BOOKMARK:([Bmk1000]),
> OBJECT:([PROD_GART_S40M0T0ODB].[dbo].[instrument]))
> |--Hash Match(Inner Join, HASH:([Bmk1000])=([Bmk1000]),
> RESIDUAL:([Bmk1000]=[Bmk1000]))
> |--Hash Match(Inner Join, HASH:([Bmk1000])=([Bmk1000]),
> RESIDUAL:([Bmk1000]=[Bmk1000]))
> | |--Index
> S(OBJECT:([PROD_GART_S40M0T0ODB].[dbo].[instrument].[pk_instrument_instrument_id]),
> SEEK:([instrument].[instrument_id] >= '4000998' AND
> [instrument].[instrument_id] <= '4000998' OR [instrument].[instrument_id] >=
> '4002121' AND
> | |--Index
> S(OBJECT:([PROD_GART_S40M0T0ODB].[dbo].[instrument].[idx_instrument_exchange_customer]),
> SEEK:([instrument].[exchange_customer] >= 'EA1' AND
> [instrument].[exchange_customer] <= 'EA1' OR [instrument].[exchange_customer]
> |--Index
> S(OBJECT:([PROD_GART_S40M0T0ODB].[dbo].[instrument].[idx_instrument_subtype_customer]),
> SEEK:([instrument].[instrument_subtype_customer] >= 'CO' AND
> [instrument].[instrument_subtype_customer] <= 'CO' OR
> [instrument].[instrument_subt
>

Ansi Nulls and quoted identified

Hello everyone,

SQL Server 2000. I have a database in which there are several objects
which have ansi nuls and quoted identifier turned ON. Is there a way I
can generate a script which:
(1) Can identify all objects within the database that have those two
properties turned ON and
(2) Change the properties for these objects and turn the ansi nulls and
quoted identifier OFF for those objects.

I am trying to avoid going throuh gazillions of objects and manually
doing this.

Thanks for any help.

Raziq.

*** Sent via Developersdex http://www.developersdex.com ***Are you sure you want to do this? It is STRONGLY recommended that both
these options always be set ON. Changing these options will break
indexed views and other code that uses them. Only use the OFF setting
for legacy code where you don't have another option.

These settings are persisted with views, procs, etc when you create
them. I think the easiest way to change them is to use Enterprise
Manager to script the database, then search and replace in the
resulting script.

--
David Portas
SQL Server MVP
--|||To identify the objects, use something like this:

SELECT name, xtype,
OBJECTPROPERTY(id,'ExecIsAnsiNullsOn'),
OBJECTPROPERTY(id,'ExecIsQuotedIdentOn')
FROM sysobjects WHERE xtype IN ('P','TR','V','IF','FN','TF')

To change these properties, you should re-create those objects using
ALTER PROCEDURE / ALTER VIEW / ALTER FUNCTION.

If you do not want to do this one by one (and if you feel particularly
lucky today, as to change an undocumented column in a system table), I
will give you a hint: bits 30 and 29 (bit mask: 0x60000000) of the
status column in the sysobjects table.

Of course, changing a system table is a bad idea (it may cause data
loss or may prevent an instance of SQL Server from running). Changing
an undocumented column of a system table is an even worse idea !

Razvan|||If you do not want to do this one by one and if you feel particularly
SUICIDAL today...

Razvan, have you actually tested out your implied suggestion? I would
NEVER recommend anyone to attempt to modify system tables directly. In
this case it is completely unnecessary.

--
David Portas
SQL Server MVP
--|||Yes, I have tested it (to turn ON those properties) and found no
side-effects.

Razvan|||Correction: I have found a side-effect:

If the procedure was executed (so the execution plan is in the
procedure cache), the change does not take effect immediately (i.e. the
old execution plan remains in the cache, until the server is restarted
or DBCC FREEPROCCACHE is executed).

However, I do not recommend this method. It is undocumented and,
therefore, not reliable. You should script the objects using Enterprise
Manager and use ALTER PROCEDURE / VIEW / FUNCTION.

Razvan|||>> turn the ansi nulls and quoted identifier OFF for those objects. <<

Why do you wish to destroy portability and data integrity? The only
reasons I can imagine are (1) ignorance of SQL (2) deliberate
sabotage. You ought ot be bringin the database into Standards
confromance, not out of it!!|||The application I am working with is designed to work with objects with
those two options turned off.

Raziq.

*** Sent via Developersdex http://www.developersdex.com ***|||>> The application I am working with is designed to work with objects with those two options turned off. <<

This is like saying that your accounting package believes that 2 + 2 =
5 so you want to change the spreadsheets and the rest of the world.

You need to re-write your code immediately, don't you? Then you need
a data audit to find out what is messed up in the Database, all of your
reports, etc.|||Right. Why don't I rewrite the application code, and then when the
application starts acting up, and we have to call the vendor, and they
say: "sorry, but this is not our code and so we can't help you." I can
tell them no problem, because I have been working on reinventing the
wheel and will be making a killing selling that new wheel and won't need
this DBA job.

One more thing, I don't think leaving the above mentioned options off
amounts to a logical inconsistency i.e. 2+2=5.

*** Sent via Developersdex http://www.developersdex.com ***|||Razvan Socol (rsocol@.gmail.com) writes:
> Yes, I have tested it (to turn ON those properties) and found no
> side-effects.

Hm, if you have a procedure that reads:

CREATE PROCEDURE ill_will AS
PRINT "Hej!"

and it was loaded with QUOTED_IDENTIFIER off, and you change it to ON,
I bet you see have side effects!

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||Raziq Shekha (raziq_shekha@.anadarko.com) writes:
> One more thing, I don't think leaving the above mentioned options off
> amounts to a logical inconsistency i.e. 2+2=5.

Oh, you don't know Joe Celko I see. In his world, 2+2=5, running with
ANSI_NULLS off or calling a table row for a record is all equally
wrong.

Then again, what could you expect from someone who thinks that IDENTITY
in SQL Server has something to do with physical location?

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||>> Why don't I rewrite the application code, and then when the application starts acting up, and we have to call the vendor, and they say: "sorry, but this is not our code and so we can't help you."<<

It is already acting up and you need to replace it ASAP. Read a nice
article at CIO magazine's website entitled "Bound to Fail" about the
falure of a legacy system that everyone could see and nobody wanted to
change.

If you are in the United States, where we have 1 lawyer for every 400
people, you should be suing this vendor.

>> I don't think leaving the above mentioned options off amounts to a logical inconsistency i.e. 2+2=5.<<

I guess that you are smarter than ANSI, smarter than ISO, smarter than
any other SQL product staff, etc. Do you exchange data with other SQL
products? Do you move data from one table to another within the system
itself? Do you plan on doing these things later? Do you want to have
a Data Warehouse someday?|||--CELKO-- (jcelko212@.earthlink.net) writes:
> It is already acting up and you need to replace it ASAP. Read a nice
> article at CIO magazine's website entitled "Bound to Fail" about the
> falure of a legacy system that everyone could see and nobody wanted to
> change.
> If you are in the United States, where we have 1 lawyer for every 400
> people, you should be suing this vendor.

So the system I work with has ANSI_NULLS off as well. I don't hear of
any customers suing us... As for why we have it, well, this is a system
that started its life in 1992, when SQL Server had nothing else to
offer.

>>> I don't think leaving the above mentioned options off amounts to a
>>> logical inconsistency i.e. 2+2=5.<<
> I guess that you are smarter than ANSI, smarter than ISO, smarter than
> any other SQL product staff, etc.

Please take your insults somewhere else. Raziq has an application, and
provided the settings which are appropriate for the system, the
application performs his job, and he is happy with it.

One thing I can tell: he is smarter than you are, because he knows what
he can change with his system and you don't.

> Do you exchange data with other SQL products? Do you move data from one
> table to another within the system itself? Do you plan on doing these
> things later? Do you want to have a Data Warehouse someday?

And how would any of that be affected by the fact that the application
internally uses NULL in the wrong way, or quotes it string literals with
" instead '?

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||>> And how would any of that be affected by the fact that the application
internally uses NULL in the wrong way, or quotes it string literals
with
" instead '? <<

IN() predicates will not work right when data is moved to the DW or to
a table with the right settings. Some of the other calculations can be
wrong.

Code will reference a column and not a literal when it is moved. My
favorite was "date" versus 'date' in one system I had to audit where
the poorly names column was a string.

Since 80% or mroe of the cost of an application is in maintaining it,
you want it to be immediately undestood by the next guy to take over
the job. Things as minor as inconsistent naming conventions can add
8-12% to the cost. What do you think that syntax that changes from
place within the application will cost?|||Thank you Erland Sommarskog. I guess Celko does not realize that there
is life outside a database and IT. Celko, you might want to look up the
following words:

1) Dating
2) dancing
3) relaxing
4) taking it easy
5) anal

And no, don't look these words up on IT.com.

Asif.

*** Sent via Developersdex http://www.developersdex.com ***|||>> Why do you wish to destroy portability and data integrity? The only
reasons I can imagine are (1) ignorance of SQL (2) deliberate
sabotage. <<

an excerpt from Real Life Databases 100 (as opposed to theoretical
databases in a perfect world):
Most software vendors discourage portability, and the reason is
obvious: they want to retain their customers, so they don't want to
make porting out of their products easy.|||--CELKO-- (jcelko212@.earthlink.net) writes:
> IN() predicates will not work right when data is moved to the DW or to
> a table with the right settings. Some of the other calculations can be
> wrong.

Presumably the DW is another database. And very likely in Analysis
Services. What the ANSI_NULLS setting is in the source system is
irrelevant.

> Code will reference a column and not a literal when it is moved. My
> favorite was "date" versus 'date' in one system I had to audit where
> the poorly names column was a string.

We already knows the answer to that one: vendor mandates which setting
that should be used.

By the same reasoning, you should never denote your tables as "Order
Details" in the code, but use [Order Details], because the code may be
loaded with QUOTED_IDENTIFIER off. (And, alas, this is the default with OSQL
and Enterprise Manager.)

> Since 80% or mroe of the cost of an application is in maintaining it,
> you want it to be immediately undestood by the next guy to take over
> the job. Things as minor as inconsistent naming conventions can add
> 8-12% to the cost. What do you think that syntax that changes from
> place within the application will cost?

That's Raziq's vendor's problem. Assume that they started to write
their application in 1992, like we did. Then " to quote strings was
a fair game in SQL Server. Guess what it would cost them to fix that?
Compare that with mandating the application to be installed with
QUOTED_IDENTIFIER off.

As it happens, our source code also uses both " and ' to delimit strings.
However, I've augmented our load tool to take replace all " with '. But
that is not really a trivial operation, and I have full understanding
for those who prefer to leave it as it is.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp

Ansi Nulls

I am get the following erro message when accessing the linked server table.
Any Suggetions ??

"HETROGENOUS QUERIES REQUIRE THE ANSI NULLS ON AND ASI WARNINGS TO BE SET FOR THE CONNETION. THIS ENSURES CONSISTENT QUERY SEMANTICS. ENABLE THESE OPTIONS AND THEN USE THE YOUR QUERY"

If Enable what go will go wrong because these are production servers..

Rajessentially you need to issue two statments:

set ANSI_NULLS on
set ANSI_WARNINGS on

I doubt setting either of these to on will give you any problems with the possability of NULL comparisons, see below.

as for what will go wrong, from Books Online:

ANSI_NULLS

When set to ON, all comparisons to a null value evaluate to NULL (unknown). When set to OFF, comparisons of non-Unicode values to a null value evaluate to TRUE if both values are NULL. By default, the ANSI_NULLS database option is OFF.

Connection-level settings (set using the SET statement) override the default database setting for ANSI_NULLS. By default, ODBC and OLE DB clients issue a connection-level SET statement setting ANSI_NULLS to ON for the session when connecting to SQL Server. For more information, see SET ANSI_NULLS.

SET ANSI_NULLS also must be set to ON when you create or manipulate indexes on computed columns or indexed views.

The status of this option can be determined by examining the IsAnsiNullsEnabled property of the DATABASEPROPERTYEX function.

and

ANSI_WARNINGS

When set to ON, errors or warnings are issued when conditions such as "divide by zero" occur or null values appear in aggregate functions. When set to OFF, no warnings are raised when null values appear in aggregate functions, and null values are returned when conditions such as "divide by zero" occur. By default, ANSI_WARNINGS is OFF.

SET ANSI_WARNINGS must be set to ON when you create or manipulate indexes on computed columns or indexed views.

Connection-level settings (set using the SET statement) override the default database setting for ANSI_WARNINGS. By default, ODBC and OLE DB clients issue a connection-level SET statement setting ANSI_WARNINGS to ON for the session when connecting to SQL Server. For more information, see SET ANSI_WARNINGS.

The status of this option can be determined by examining the IsAnsiWarningsEnabled property of the DATABASEPROPERTYEX function.

ANSI Nulls

I've mentioned this before, but now it's got me stuck. I have a
table-valued function that was created using QA in SQL 2000. I can't
edit it using 2005 Mgt Studio, because the property AnsiNullsStatus
isn't set (apparently SQL 2000 forgot to set it when creating the
function). Now I find I really want to edit it in SQL 2005 MS without
going to SQL 2000 QA on my laptop. So, using SQL 2005 MS, I dropped
and re-created the function, having obtained the code from SQL 2000 QA.
That should fix this, right? When SQL 2005 re-creates the function, it
will specify whatever it needs. But no, I still can't edit it! The
property is still not set!

Can anyone help? Please?

Thanks,
Jim GeissmanHello, Jim

It's a known bug. See:
http://lab.msdn.microsoft.com/Produ...ackid=FDBK38845

Microsoft tried to fix it in SQL Server 2005 SP1, but did not fully
succeed. However, on SP1 you can script the function in Management
Studio, by choosing "Script function as Create" (but it still doesn't
work with "Modify" or "Script function as Alter").

Razvan|||Thank you, Razvan.