473,396 Members | 1,892 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,396 software developers and data experts.

Getting check constraint error from sproc?

zachster17
Hello everybody,

I was wondering if it was possible to get the name of the check constraint that caused an error (if it was the cause of an error) in a stored procedure as a way to handle errors.

For example, I have a stored procedure that adds a record to a table and I'd like to have a more user-friendly error message than just showing the error name, which still is useful.

Thank you,

Zach
Jul 19 '08 #1
5 2019
ck9663
2,878 Expert 2GB
Check out Try...Catch

Here are also some good reference.

-- CK
Jul 19 '08 #2
Check out Try...Catch

Here are also some good reference.

-- CK
I checked out the TRY/CATCH but I'm stuck with SQL Server 2000 for this job, so I can't use this. Is there anyway to capture the name of a check constraint using the 2000 method (of checking @@ERROR) before the constraint actually stops the stored procedure (without doing a trigger of sorts?)
Jul 20 '08 #3
Delerna
1,134 Expert 1GB
You could always do your error checking in the stored proc itself and return your own sensible error messages back to the front end.
Jul 20 '08 #4
You could always do your error checking in the stored proc itself and return your own sensible error messages back to the front end.

Thanks Delerna--that seems like the only way. I'm kind of inexperienced when it comes to working in companies with SQL Server, but is it standard to do a lot of validating/error checking in stored procedures (instead of enforcing rules through table constraints and keys, etc.)

Zach
Jul 21 '08 #5
Delerna
1,134 Expert 1GB
No, not instead of. Setting up table constraints,keys and relationships is very important. But as you mention in your post, left to its own devices, SQL server dosn't supply the friendliest of error messages back to a front end. So what I was refering to is more in "addition to" so that you as the developer can supply friendlier error messages (in situations where that is important) to your users.
Jul 21 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Hari Om | last post by:
Hi ORAPERTS (ORAcle xPERTS) How can I define a CHECK CONSTRAINT on a table for a field like zip code....? Here is what I am doing: create table test ( state varchar2(5) check (state...
2
by: Doug Baroter | last post by:
Hi, DDLs and DMLs: create table #job (jobID int identity(1,1) primary key, jobName varchar(25) unique not null, jobEndDate dateTime, jobComplete bit default(0), check (( is null and = 0) OR (...
3
by: RAD | last post by:
I am working with an evaluation copy of SQL Server 2000 for the first time; my DB experience lies with MS Access. I have a simple table in SQL Server (tblCompany) that has a field called...
0
by: Fabre Lambeau | last post by:
I've got a problem when adding a CONSTRAINT CHECK on a table by calling a function. It just seems not to work... Here is the table (simplified to only the relevant fields for this case): ...
2
by: Robert Fitzpatrick | last post by:
I have a field in my pgsql 7.4.2 table that is char(6) type. This holds an ID that contains only numbers, but must be six characters in length. First two chars are the year followed by a sequential...
13
by: dbuchanan | last post by:
Hello, Here is the error message; ---------------------------- Exception Message: ForeignKeyConstraint Lkp_tbl040Cmpt_lkp302SensorType requires the child key values (5) to exist in the...
3
by: ferg | last post by:
I have a Customer table. The table has two different CHECK constraints. Then there is the Customer details dialog, which provides the user with an UI for changing users. I have some UPDATE sql,...
1
by: Spectre1337 | last post by:
Hello, it seems like the check constraint validation of MS SQL Server Management Studio express is horribly, horribly broken. Either that or I'm using it wrong. I hope it's the latter. I'm...
3
by: kbcompany | last post by:
Hi I have just started learning oracle. i have created a table with name imp_master and columns item_code with constraint not null, item_name with constraint n1 not null(n1 is user...
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: 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...
0
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...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.