January 12, 2004 at 4:12 am
i've started studying SQL Server 2000, i'm stuck with problem. i need to display an error message when an invlaild ID is entered. I know i'm ment to use a trigger for this but not sure on where to start.....
Yes this is on a primary key, and i think it will be best to test it before we put in the data file.
I would like to validate the entry from the foriegn key, to see if it exists, but it cannot be 0 or ant thing other than numbers.
I hope i,ve helped. Please feel free to contact me for any futher info.
January 12, 2004 at 6:04 am
I'm not sure if I understand you.
Do you want to test before actually inserting?
Is the ID some kind of key?
Can you give some more information?
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
January 12, 2004 at 12:26 pm
Normally it's best to autogenerate the primary keys use identity columns if you are not in any way allowing users of your application to use them directly. You can define constraints on your column to put some validations.
Hope this helps.
You have to dig for tons of dirt to get an ounce of Gold
January 14, 2004 at 9:36 am
hi!
hope i got your question right. normally, when designing your database, you'd use a numeric field as your primary key in that case. this prohibits entering anything else but digits.
once you create a primary key on that field (remember: primary keys are not only indexes, but also constraints enforcing uniqueness of values), you'll simply not be able to have duplicate values in that field.
so, you won't have to check anything in a trigger before inserting, as SQL server will inform you on attempt of insertion of any violations of those conditions.
best regards, chris.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply