Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Limiting entries into the column
Message
From
28/02/2003 13:31:26
 
General information
Forum:
Microsoft SQL Server
Category:
Database design
Miscellaneous
Thread ID:
00759382
Message ID:
00759540
Views:
16
>If my field can be either Y or N, how can I specify it? Or if the field can be only one of 3 predefined values?

Do you want to limit the column to only containing one of those discrete values? If so, you'll want to add a CHECK constraint to the table:

CREATE TABLE mytable (
gender nchar(1) CHECK(gender IN ('m', 'f'))
...
)

>Also, is it right to create one index with three columns? One of the fields is FK, two others just regular fields, but may be useful in joins or where clause...

Tricking question. What would be the definition of "right?" SQL Server does support composite indexes. The real question is whether the query optimizer will decide that the index is usable and that decision will be on a per query basis.

-Mike

>Hi everybody,
>
>If my field can be either Y or N, how can I specify it? Or if the field can be only one of 3 predefined values?
>
>Also, is it right to create one index with three columns? One of the fields is FK, two others just regular fields, but may be useful in joins or where clause...
>
>I've generated relationship:
>ALTER TABLE dbo.CartDetail ADD CONSTRAINT
>	FK_CartDetail_CartContent FOREIGN KEY
>	(
>	CartContentID
>	) REFERENCES dbo.CartContent
>	(
>	CartContentID
>	) ON UPDATE CASCADE
>	 ON DELETE CASCADE
>	
>GO
>
>It is the same, as triggers? Or should I do something different?
>
>
>
>Thanks in advance.
Michael Levy
MCSD, MCDBA
ma_levy@hotmail.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform