473,383 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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 ***
Aug 8 '05 #1
17 4531
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
--

Aug 8 '05 #2
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

Aug 8 '05 #3
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
--

Aug 8 '05 #4
Yes, I have tested it (to turn ON those properties) and found no
side-effects.

Razvan

Aug 8 '05 #5
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

Aug 8 '05 #6
>> 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!!

Aug 8 '05 #7
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 ***
Aug 8 '05 #8
>> 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.

Aug 8 '05 #9
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 ***
Aug 8 '05 #10
Razvan Socol (rs****@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, es****@sommarskog.se

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

Aug 8 '05 #11
Raziq Shekha (ra**********@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, es****@sommarskog.se

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

Aug 8 '05 #12
>> 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?

Aug 9 '05 #13
--CELKO-- (jc*******@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, es****@sommarskog.se

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

Aug 9 '05 #14
>> 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?

Aug 9 '05 #15
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 ***
Aug 9 '05 #16
AK
>> 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.

Aug 9 '05 #17
--CELKO-- (jc*******@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, es****@sommarskog.se

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

Aug 9 '05 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

100
by: Roose | last post by:
Just to make a tangential point here, in case anyone new to C doesn't understand what all these flame wars are about. Shorthand title: "My boss would fire me if I wrote 100% ANSI C code" We...
4
by: Luke Wu | last post by:
I am just wondering what the following terms usually mean: 1) "Standard C" 2) "K&R C" 3) "ANSI C" I am pretty sure "ANSI C" usually refers to the C89 standard, but what
0
by: tphilipose | last post by:
Dear Friends, I have a table in which is having some fields which does not allow nulls. I need to make few of them TO ALLOW NULLS I went throug SQL Server Enterprise Manager, then right click on...
8
by: shira | last post by:
I have done a fair bit of searching, but haven't yet been able to find an explanation as to why one would set "ignore nulls" to "yes" when creating an index. I understand what it does (I think),...
6
by: Satish | last post by:
Hi , What is the behaviour as per ANSI standard for HUGE_VAL * 0.0? Also is there anywhere I can download ANSI standards for C/C++? Thanks, Satish
127
by: bz800k | last post by:
Hi Does this code satisfy ANSI C syntax ? void function(void) { int a = 2; a = ({int c; c = a + 2;}); /* <<-- here !! */ printf("a=%d\n", a);
6
by: othellomy | last post by:
create table t1(c1 int, c2 varchar(10)) insert t1 values(1,'Hello') insert t1 values(2,'') insert t1 values(3,NULL) select * from t1 c1 c2 1 Hello
6
by: Cliff72 | last post by:
I need to fill in the nulls in the batch field the value from the record immediately preceding the null one ie replace the nulls with the preceding value until I hit a record with a value in...
4
by: =?Utf-8?B?R2lubw==?= | last post by:
I have written an application which uses a streamwriter to create which is exported to a third party system. The third party system does not appear to process the files in its original format. I...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.