473,651 Members | 2,658 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How does adding constraints affect performance?

I'm considering adding domain integrity checks to some of my database table
items. How does adding such constraints affect SQL Server performance? For
example, I have a simple constraint that restricts a couple of columns to
having values within the values assigned in my application by an
enumeration:

(([Condition] >= 0 and [Condition] <=3) and ([Type] >= 0 and [Type] <=
2))

This enforces domain integrity for two enumerations having values 0, 1, 2, 3
and 0, 1, 2 in the application. Is this an efficient way of performing such
checks? What are the pitfalls of domain integrity checking?
Thanks


Robin

Jul 23 '05 #1
1 3878
Robin Tucker (id************ *************@r eallyidont.com) writes:
I'm considering adding domain integrity checks to some of my database
table items. How does adding such constraints affect SQL Server
performance? For example, I have a simple constraint that restricts a
couple of columns to having values within the values assigned in my
application by an enumeration:

(([Condition] >= 0 and [Condition] <=3) and ([Type] >= 0 and [Type] <=
2))
Two pieces of advice:

1) Fewer parentheses!
2) Make that two constraints. If nothing else, this is good when the
check fails, since you more easily can tell what went wrong.
This enforces domain integrity for two enumerations having values 0, 1, 2, 3 and 0, 1, 2 in the application. Is this an efficient way of performing
such checks? What are the pitfalls of domain integrity checking?


CHECK constraints is probably the most effcient way of performing checks
of this kind.

CHECK constraints can also help to improve performance. Presuming that you
don't add your constraints WITH NOCHECK, this SELECT on large table will
return promptly:

SELECT * FROM tbl WHERE Type = 4

Not that this is the most likely query...

--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #2

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

Similar topics

0
1136
by: mmike | last post by:
How does the ASP.NET output cache affect an httpS:// (SSL) connection? Suppose I have a default.aspx page that has the following: <%@OutputCache Duration="3600" VaryByParam="None" %> Page_Load { /* if 443 convert to http:// via Response.Redirect(..........) */ blah ......redirect to a simple port 80 connection as opposed to a 443
2
1858
by: Brian Maguire | last post by:
Could someone provide me with some information in regards to the performance implications of applying constraints on a table? Are there any safe guards? The basic scenario is that there is a table that has 80% updates and inserts and 20% selects. I would like to restrict duplicate inserts from user double clicking or other user behavior such as refresh. I am after advice on what the performance implications would be on placing...
4
3850
by: David Link | last post by:
Hi, Why does adding SUM and GROUP BY destroy performance? details follow. Thanks, David Link s1.sql: SELECT t.tid, t.title, COALESCE(s0c100r100.units, 0) as w0c100r100units,
7
7142
by: Dima | last post by:
Call to XmlNode.GetElementsByTagName returns XmlNodeList that stays in sync with XmlDocument thanks to events fired by XmlDocument. Once this list is created there is no way to remove its event handlers from the document. Calling GetElementsByTagName second time for the same tag name will create new list and add more event handlers. As result over time these handlers accumulate and reach pretty high number (millions). Every modification...
5
1435
by: Paul Reddin | last post by:
Hi, We have noticed some of our complex queries run much faster when connected as the instance owner, compared to a userA who has explcitly granted privileges on all the required Tables & SQL Table Functions. e.g 1 query runs in 10ms for the Instance Owner and 1.9s for the user i.e greater than 100x faster!
3
1313
by: James dean | last post by:
From what i have read and seen the JIT compiler is very efficient and only compiles that code that it needs at runtime therefore it helps, not hinders performance. Does the JIT compiler make Gdi+ slower in any way?. *** Sent via Developersdex http://www.developersdex.com ***
11
11156
by: Raja Chandrasekaran | last post by:
Hai folks, I have a question to get exact answer from you people. My question is How Static class is differ from instance class and If you use static class in ASP.NET, ll it affect speed or performance of site...? Because I am using static class in my Database layer. But one of my friend told me that "static class ll take more space than instance class and it ll affect the performance. But if you use Instance class
1
2808
by: Ray99 | last post by:
How does Ruby operator affect overall program readability?
0
1596
by: kleach | last post by:
If I have a large(200gb), medium width(300 bytes) table and need to add a column, we have always unloaded data, dropped and recreated the table then loaded data again to ensure performance. What is the cost of using alter table on future queries?
0
8352
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8697
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8579
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6158
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5612
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4283
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2699
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1909
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.