Sunday, February 26, 2012

ENABLE/DISABLE primarykeys,foreignkeys & indexes

hi,
I need to ENABLE & Disable the primarykeys,foreignkeys & indexes of a table
I have tried
ALTER TABLE employees DISABLE PRIMARY KEY
but it shows the following error
Incorrect syntax near the keyword 'PRIMARY'.
can u help me?
Thanks,
SouraAs a primary key is supported by a unique index, you cannot disable it. A
unique index has to always enforce uniqueness.
Please check the proper syntax in the Books Online. DISABLE is only used for
triggers.
To disable a constraint, you must use the NOCHECK option. And the BOL
states:
{ CHECK | NOCHECK} CONSTRAINT
Specifies that constraint_name is enabled or disabled. When disabled, future
inserts or updates to the column are not validated against the constraint
conditions. This option can only be used with FOREIGN KEY and CHECK
constraints.
To no longer enforce the primary key's properties, you have to DROP the
constraint, which will drop the unique index.
Please see BOL for complete syntax details.
--
HTH
--
Kalen Delaney
SQL Server MVP
www.SolidQualityLearning.com
"SouRa" <SouRa@.discussions.microsoft.com> wrote in message
news:3CA0935E-35E9-46D4-8D2F-DD317FECFAB1@.microsoft.com...
> hi,
> I need to ENABLE & Disable the primarykeys,foreignkeys & indexes of a
> table
> I have tried
> ALTER TABLE employees DISABLE PRIMARY KEY
> but it shows the following error
> Incorrect syntax near the keyword 'PRIMARY'.
> can u help me?
> Thanks,
> Soura
>|||hi,
I need to DISABLE/ENABLE all the foreign keys in a DataBase
Is it possible through Query?
Can u help me?
Thanks
Soura
"Kalen Delaney" wrote:
> As a primary key is supported by a unique index, you cannot disable it. A
> unique index has to always enforce uniqueness.
> Please check the proper syntax in the Books Online. DISABLE is only used for
> triggers.
> To disable a constraint, you must use the NOCHECK option. And the BOL
> states:
> { CHECK | NOCHECK} CONSTRAINT
> Specifies that constraint_name is enabled or disabled. When disabled, future
> inserts or updates to the column are not validated against the constraint
> conditions. This option can only be used with FOREIGN KEY and CHECK
> constraints.
> To no longer enforce the primary key's properties, you have to DROP the
> constraint, which will drop the unique index.
> Please see BOL for complete syntax details.
> --
> HTH
> --
> Kalen Delaney
> SQL Server MVP
> www.SolidQualityLearning.com
>
> "SouRa" <SouRa@.discussions.microsoft.com> wrote in message
> news:3CA0935E-35E9-46D4-8D2F-DD317FECFAB1@.microsoft.com...
> > hi,
> >
> > I need to ENABLE & Disable the primarykeys,foreignkeys & indexes of a
> > table
> >
> > I have tried
> > ALTER TABLE employees DISABLE PRIMARY KEY
> >
> > but it shows the following error
> > Incorrect syntax near the keyword 'PRIMARY'.
> >
> > can u help me?
> >
> > Thanks,
> > Soura
> >
>
>

No comments:

Post a Comment