I use to know how to do this in oracle, but cant remember... how do i set up
a constraint on a column in a table so it can say only be
"START","STOP","INPROG" only as the text that column can have? thanks!Brian
Does it relate to SQL Server ?
"Brian Henry" <nospam@.nospam.com> wrote in message
news:OZNGmLq7FHA.4076@.tk2msftngp13.phx.gbl...
>I use to know how to do this in oracle, but cant remember... how do i set
>up a constraint on a column in a table so it can say only be
>"START","STOP","INPROG" only as the text that column can have? thanks!
>|||yes? why wouldn't a constraint on a column relate to sql server
"Uri Dimant" <urid@.iscar.co.il> wrote in message
news:uIV5pPq7FHA.2176@.TK2MSFTNGP14.phx.gbl...
> Brian
> Does it relate to SQL Server ?
>
> "Brian Henry" <nospam@.nospam.com> wrote in message
> news:OZNGmLq7FHA.4076@.tk2msftngp13.phx.gbl...
>|||I not 100% shure but something like this should work !ALTER TABLE your_table
ADD CONSTRAINT CK_emp_id CHECK (colum_name='START' or colum_name='STOP' or
colum_name='INPROG')
Regards,Predrag Stojanovic"Brian Henry" <nospam@.nospam.com> wrote in message
news:OZNGmLq7FHA.4076@.tk2msftngp13.phx.gbl...
> I use to know how to do this in oracle, but cant remember... how do i set
up
> a constraint on a column in a table so it can say only be
> "START","STOP","INPROG" only as the text that column can have? thanks!
>|||Seems that you are looking for CHECK constraints.
Here is details about Check Constraint from BOL:
CHECK constraints enforce domain integrity by limiting the values that are
accepted by a column. They are similar to FOREIGN KEY constraints in that
they control the values that are placed in a column. The difference is in ho
w
they determine which values are valid: FOREIGN KEY constraints get the list
of valid values from another table, and CHECK constraints determine the vali
d
values from a logical expression that is not based on data in another column
.
For example, it is possible to limit the range of values for a salary column
by creating a CHECK constraint that allows only data that ranges from $15,00
0
through $100,000. This prevents salaries from being entered beyond the norma
l
salary range.
You can create a CHECK constraint with any logical (Boolean) expression that
returns TRUE or FALSE based on the logical operators. For the previous
example, the logical expression is:
salary >= 15000 AND salary <= 100000
And here is an example from BOL:
This example specifies that the pub_id must be within a specific list or
follow a given pattern. This constraint is for the pub_id of the publishers
table.
CHECK (pub_id IN ('1389', '0736', '0877', '1622', '1756')
OR pub_id LIKE '99[0-9][0-9]')
"Brian Henry" wrote:
> yes? why wouldn't a constraint on a column relate to sql server
>
> "Uri Dimant" <urid@.iscar.co.il> wrote in message
> news:uIV5pPq7FHA.2176@.TK2MSFTNGP14.phx.gbl...
>
>|||thanks thats what i was looking for
"Absar Ahmad" <AbsarAhmad@.discussions.microsoft.com> wrote in message
news:CBFE5462-107B-439B-B980-60882F0CA9FA@.microsoft.com...
> Seems that you are looking for CHECK constraints.
> Here is details about Check Constraint from BOL:
> CHECK constraints enforce domain integrity by limiting the values that are
> accepted by a column. They are similar to FOREIGN KEY constraints in that
> they control the values that are placed in a column. The difference is in
> how
> they determine which values are valid: FOREIGN KEY constraints get the
> list
> of valid values from another table, and CHECK constraints determine the
> valid
> values from a logical expression that is not based on data in another
> column.
> For example, it is possible to limit the range of values for a salary
> column
> by creating a CHECK constraint that allows only data that ranges from
> $15,000
> through $100,000. This prevents salaries from being entered beyond the
> normal
> salary range.
> You can create a CHECK constraint with any logical (Boolean) expression
> that
> returns TRUE or FALSE based on the logical operators. For the previous
> example, the logical expression is:
> salary >= 15000 AND salary <= 100000
> And here is an example from BOL:
> This example specifies that the pub_id must be within a specific list or
> follow a given pattern. This constraint is for the pub_id of the
> publishers
> table.
> CHECK (pub_id IN ('1389', '0736', '0877', '1622', '1756')
> OR pub_id LIKE '99[0-9][0-9]')
> "Brian Henry" wrote:
>sql
No comments:
Post a Comment