Hi. In a table called Groups with fields GroupID (PK), Name, how can I set a
Constraint to make Name filed Unique to avoid:
GroupID | Name
==========
1 | Admin
2 | AdminCheck out ALTER TABLE in BooksOnLine and look at the CONSTRAINT section.
Here is an example directly from BOL:
CREATE TABLE doc_exc ( column_a INT)
GO
ALTER TABLE doc_exc ADD column_b VARCHAR(20) NULL
CONSTRAINT exb_unique UNIQUE
Andrew J. Kelly SQL MVP
"KenA" <KenA@.discussions.microsoft.com> wrote in message
news:1DD9B537-20E5-4010-A469-03C4259F2C3D@.microsoft.com...
> Hi. In a table called Groups with fields GroupID (PK), Name, how can I set
a Constraint to make Name filed Unique to avoid:
> GroupID | Name
> ==========
> 1 | Admin
> 2 | Admin|||Thanks Andrew:
But suppose that I already have the 'doc_exc' Table created, but still haven
′t add a constraint to column_b ... I can find a way to add the constraint,
unless I delete the table and run the script again?
KenA.
"Andrew J. Kelly" wrote:
> Check out ALTER TABLE in BooksOnLine and look at the CONSTRAINT section.
> Here is an example directly from BOL:
> CREATE TABLE doc_exc ( column_a INT)
> GO
> ALTER TABLE doc_exc ADD column_b VARCHAR(20) NULL
> CONSTRAINT exb_unique UNIQUE
>
> --
> Andrew J. Kelly SQL MVP
>
> "KenA" <KenA@.discussions.microsoft.com> wrote in message
> news:1DD9B537-20E5-4010-A469-03C4259F2C3D@.microsoft.com...
> a Constraint to make Name filed Unique to avoid:
>
>|||In that case, just run the Alter table command alone.
John
"KenA" <KenA@.discussions.microsoft.com> wrote in message
news:B982E393-F58D-4224-A883-32E8B10AAAB7@.microsoft.com...
> Thanks Andrew:
> But suppose that I already have the 'doc_exc' Table created, but still
havent add a constraint to column_b ... I can find a way to add the
constraint, unless I delete the table and run the script again?[vbcol=seagreen]
> KenA.
> "Andrew J. Kelly" wrote:
>
set[vbcol=seagreen]
No comments:
Post a Comment