February 28, 2008 at 1:10 pm
I need to help with a script;
I wish for the script to first check 3 different columns and not allow any type of update to the database if there is a match....
February 28, 2008 at 2:18 pm
Let's rephrase that to see if I'm hearing the question correctly.
Are you looking to simply enforce uniqueness across those three columns? If you simply create a UNIQUE CONSTRAINT on those three fields -
alter table MyTable
add CONSTRAINT uc_MyTable unique (col1,col2,col3)
This will prevent anyone inserting or updating rows to something that would result in duplicates across col1, col2, col3
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
February 28, 2008 at 2:37 pm
Matt's solution will cause an error to be thrown whenever the constraint is validated so you will want to catch the error.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
February 29, 2008 at 11:57 am
Msg 1919, Level 16, State 1, Line 1
Column 'Application_Name' in table 'Vista Application Compatibility' is of a type that is invalid for use as a key column in an index.
Msg 1750, Level 16, State 0, Line 1
Could not create constraint. See previous errors.
what wrong with my columns is the datatype incorrect. I am using text.
February 29, 2008 at 12:12 pm
You cannot index a text datatype. The TEXT datatype is stored as binary data and was intended mainly to store documents, etc.. and is being deprecated. It also needs to be manipulated using special functions (READTEXT, WRITETEXT). So if you don't have to have unlimited storage, get away from the TEXT datatype.
In SQL Server 2005 you should be using varchar(max). You really should evaluate if you really need that much storage space for a single column though. If you are actually just storing an application name varchar(100) should be more than adequate. Best practice is to limit row width by sizing your columns appropriately.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply