Home All Groups Group Topic Archive Search About
Author
24 Mar 2006 1:53 AM
Eric_Singapore
Hi all,

I have created a table and I need to make amendments to one of the attributes. The attribute is set to accept integers but now I have to change to accept only integers greater than zero. May I know how do I make this change?


Thanks -- Eric_Singapore ------------------------------------------------------------------------ Posted via http://www.codecomments.com ------------------------------------------------------------------------

Author
24 Mar 2006 7:54 AM
lara169
You can create a check constrint for that columns

ALTER TABLE urTable WITH NOCHECK -- puting nocheck option will disable
checking of existing data
ADD CONSTRAINT urConstraintName CHECK ( urColumnName > 0)

lara

Show quote
"Eric_Singapore" <Eric_Singapore.255***@mail.codecomments.com> wrote in
message news:Eric_Singapore.255nxr@mail.codecomments.com...
>
> Hi all,
>
> I have created a table and I need to make amendments to one of the
> attributes. The attribute is set to accept integers but now I have to
> change to accept only integers greater than zero. May I know how do I
> make this change?
>
>
> Thanks
>
>
>
> --
> Eric_Singapore
> ------------------------------------------------------------------------
> Posted via http://www.codecomments.com
> ------------------------------------------------------------------------
>
Author
24 Mar 2006 1:27 PM
Wayne Snyder
I always make it a practice to NAME constaints so I might be able to tell
what the deal is from the constraint name... So I'd make a little change to
lara's suggestion


ALTER TABLE urTable WITH NOCHECK -- puting nocheck option will disable
checking of existing data
ADD CONSTRAINT ValueMustBeGreaterThanZero CHECK ( urColumnName > 0)


--
Wayne Snyder MCDBA, SQL Server MVP
Mariner, Charlotte, NC

I support the Professional Association for SQL Server ( PASS) and it''s
community of SQL Professionals.


Show quote
"lara169" wrote:

> You can create a check constrint for that columns
>
> ALTER TABLE urTable WITH NOCHECK -- puting nocheck option will disable
> checking of existing data
> ADD CONSTRAINT urConstraintName CHECK ( urColumnName > 0)
>
> lara
>
> "Eric_Singapore" <Eric_Singapore.255***@mail.codecomments.com> wrote in
> message news:Eric_Singapore.255nxr@mail.codecomments.com...
> >
> > Hi all,
> >
> > I have created a table and I need to make amendments to one of the
> > attributes. The attribute is set to accept integers but now I have to
> > change to accept only integers greater than zero. May I know how do I
> > make this change?
> >
> >
> > Thanks
> >
> >
> >
> > --
> > Eric_Singapore
> > ------------------------------------------------------------------------
> > Posted via http://www.codecomments.com
> > ------------------------------------------------------------------------
> >
>
>
>
Author
24 Mar 2006 3:09 PM
ML
The NOCHECK option, personally, makes no sense to me - "enforce a rule but
not just yet"? IMHO existing values should be checked (and repaired if
needed) before a constraint is added.

But I could be wrong.


ML

---
http://milambda.blogspot.com/
Author
24 Mar 2006 3:22 PM
Raymond D'Anjou
"ML" <M*@discussions.microsoft.com> wrote in message
news:BCF85086-F4BE-4FDB-906D-F95AEAF9F166@microsoft.com...
> The NOCHECK option, personally, makes no sense to me - "enforce a rule but
> not just yet"? IMHO existing values should be checked (and repaired if
> needed) before a constraint is added.
>
> But I could be wrong.
>
>
> ML
>

I've always wondered why that option was offered.
Glad to see that I'm not alone.
Author
24 Mar 2006 3:40 PM
ML
Yeah, imagine using that option when picking up your kids from school.


ML

---
http://milambda.blogspot.com/
Author
24 Mar 2006 3:46 PM
Raymond D'Anjou
"ML" <M*@discussions.microsoft.com> wrote in message
news:850594CF-BD71-437B-97FE-256143D2C93A@microsoft.com...
> Yeah, imagine using that option when picking up your kids from school.
>
>
> ML

You have a STRANGE sense of humour ML.
Or is it because it's Friday and it's early in your neck of the woods.
Have a coffee... or two.
Author
24 Mar 2006 4:02 PM
ML
It's 16:58 over here. As far as coffee is concerned in deed I need a re-fill,
but that doesn't change the fact that coming home with the wrong set of
children just isn't good practice.

:)


ML

---
http://milambda.blogspot.com/
Author
24 Mar 2006 4:08 PM
Raymond D'Anjou
"ML" <M*@discussions.microsoft.com> wrote in message
news:A2214788-E91D-4E18-98E7-4175142CD0D8@microsoft.com...
> It's 16:58 over here. As far as coffee is concerned in deed I need a
> re-fill,
> but that doesn't change the fact that coming home with the wrong set of
> children just isn't good practice.
>
> :)
>
>
> ML

Practice for what???
Author
24 Mar 2006 4:21 PM
ML
At what point have I lost you? I guess it was a bad example...

NOCHECK in SQL = existing data is not checked.

NOCHECK in real life = criminal act.


ML

---
http://milambda.blogspot.com/
Author
24 Mar 2006 4:30 PM
Raymond D'Anjou
"ML" <M*@discussions.microsoft.com> wrote in message
news:FFA03BC3-F6EE-47A3-A70C-1D7334D6138D@microsoft.com...
> At what point have I lost you? I guess it was a bad example...
>
> NOCHECK in SQL = existing data is not checked.
>
> NOCHECK in real life = criminal act.
>
>
> ML

I was just trying to prove that there may be stranger "senses of humour"
than yours.   :-)
Author
24 Mar 2006 4:42 PM
ML
ROFL! :D

Well, you've succeeded. I think I've just dislocated my pancreas laughing.


ML

---
http://milambda.blogspot.com/
Author
24 Mar 2006 7:02 PM
Tibor Karaszi
> I've always wondered why that option was offered.

How about if you want to extend the domain of allowable values (like used to allow 0-10, now allows
0-15)? If you are alone while removing the old and adding the new constraint, you know that no rows
violates the new constraint. And, assume some 200 million rows in the table. :-)

Show quote
"Raymond D'Anjou" <rdanjou@canatradeNOSPAM.com> wrote in message
news:OO$Hwc1TGHA.5884@TK2MSFTNGP14.phx.gbl...
> "ML" <M*@discussions.microsoft.com> wrote in message
> news:BCF85086-F4BE-4FDB-906D-F95AEAF9F166@microsoft.com...
>> The NOCHECK option, personally, makes no sense to me - "enforce a rule but
>> not just yet"? IMHO existing values should be checked (and repaired if
>> needed) before a constraint is added.
>>
>> But I could be wrong.
>>
>>
>> ML
>>
>
> I've always wondered why that option was offered.
> Glad to see that I'm not alone.
>
Author
24 Mar 2006 7:16 PM
Raymond D'Anjou
Very good point Tibor.
I'll go to bed a bit less dense tonight.

Show quote
"Tibor Karaszi" <tibor_please.no.email_kara***@hotmail.nomail.com> wrote in
message news:%23BFB3V3TGHA.2276@tk2msftngp13.phx.gbl...
>> I've always wondered why that option was offered.
>
> How about if you want to extend the domain of allowable values (like used
> to allow 0-10, now allows 0-15)? If you are alone while removing the old
> and adding the new constraint, you know that no rows violates the new
> constraint. And, assume some 200 million rows in the table. :-)
>
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> Blog: http://solidqualitylearning.com/blogs/tibor/
>
>
> "Raymond D'Anjou" <rdanjou@canatradeNOSPAM.com> wrote in message
> news:OO$Hwc1TGHA.5884@TK2MSFTNGP14.phx.gbl...
>> "ML" <M*@discussions.microsoft.com> wrote in message
>> news:BCF85086-F4BE-4FDB-906D-F95AEAF9F166@microsoft.com...
>>> The NOCHECK option, personally, makes no sense to me - "enforce a rule
>>> but
>>> not just yet"? IMHO existing values should be checked (and repaired if
>>> needed) before a constraint is added.
>>>
>>> But I could be wrong.
>>>
>>>
>>> ML
>>>
>>
>> I've always wondered why that option was offered.
>> Glad to see that I'm not alone.
>>
>
Author
26 Mar 2006 10:56 PM
ML
Yes, this does make sense - extending the constraint. Good to know, thanks.


ML

---
http://milambda.blogspot.com/
Author
24 Mar 2006 8:56 AM
ML
Add a check constraint:

alter table <table name>
  add constraint <constrait name>
                        check (<column name> > 0)
go


ML

---
http://milambda.blogspot.com/

AddThis Social Bookmark Button