Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


INSERTING VALUES IN A TABLE USING CHECK CONSTRAINT


INSERTING VALUES IN A TABLE USING CHECK CONSTRAINT

Author
Message
georgevarghese3
georgevarghese3
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 25
HELLO MY NAME IS GEORGE BEGINNER IN SQL

MY QUESTION IS THAT ,I WANT TO CREATE A TABLE WITH ONE FIELD WHICH HAS TO INSERT ONLY THREE VALUES AFTER THAT FIELD INSERT THRE VALUES IT SHOULD NOT BE ABLE TO INSERT MORE VALUES

IN DETAIL IF MY TABLE NAME IS 'SOURCE' WHICH CONTAIN ONLY ONE FIELD, NAMED 'CATEGORY'OF TYPE VARCHAR I ONLY WANT TO ENTER THREE VALUES IN THIS AS 'LAND','AIR','WATER' I SHOULD BE ABLE TO INSERT ONLY THIS VALUES AND TEHRE SHOULD BE NO DUPLICATION OF THESE VALUES AND NO OTHER VALUES SHOULD BE INSERTED IS IT POSSIBLE USING CHECK CONSTRAINT . IF NOT USING STORED PROCEDURES

I AM EXPECTING AN EARLY REPLY
Lowell
Lowell
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14955 Visits: 38949
this sounds very much like a homework assignment....
aside from that...
you want to do a few things....

you said only three specific values.... as you suspected, read about CHECK CONTRAINTS in you books online.
you might also want to make the column NOT NULL when you build the table, so it cannot be blasnk either.

to force a column to be unique, you'll want to read about UNIQUE CONSTRAINTS in books online as well.
the combination of those three should get you where you want to go.

show us what you've built so far and we could offer some more insight.

Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

GilaMonster
GilaMonster
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47213 Visits: 44370
And please don't post in all caps. It's the online equivalent of shouting at someone. It's also hard to read.


Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search