Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

INSERTING VALUES IN A TABLE USING CHECK CONSTRAINT Expand / Collapse
Author
Message
Posted Friday, October 17, 2008 5:40 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Sunday, August 24, 2014 7:57 AM
Points: 2, Visits: 14
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
Post #587537
Posted Friday, October 17, 2008 5:56 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 5:47 PM
Points: 12,910, Visits: 32,020
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

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #587549
Posted Friday, October 17, 2008 9:09 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 2:38 AM
Points: 42,832, Visits: 35,963
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 2008, MVP
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

Post #587724
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse