Home All Groups Group Topic Archive Search About

how do I check if constraints exists?

Author
24 Nov 2005 5:01 AM
Hans [DiaGraphIT]
Hi!

I want to create constraints, but I want to check if the constraint exists
first.  How do I do that? 

I think something like following example would work for me, but I'm not sure
how to check... filling the space between ...exists (...)

IF NOT EXISTS (.......)
ALTER TABLE UserTable
    ADD CONSTRAINT Language_UserTable FOREIGN KEY (fk_LanguageID) REFERENCES
Language (LanguageID) ON DELETE CASCADE ON UPDATE CASCADE
GO

Please help
---------------
Best regards
- Hans -
---------------

Author
24 Nov 2005 5:18 AM
Uri Dimant
Hans
Take a look at INFORMATION_SCHEMA.TABLE_CONSTRAINTS view


Show quote
"Hans [DiaGraphIT]" <hans.ar***@sshf.no> wrote in message
news:ABFCB48A-590E-4C05-B308-A40C67ED3C41@microsoft.com...
> Hi!
>
> I want to create constraints, but I want to check if the constraint exists
> first.  How do I do that?
>
> I think something like following example would work for me, but I'm not
> sure
> how to check... filling the space between ...exists (...)
>
> IF NOT EXISTS (.......)
> ALTER TABLE UserTable
>    ADD CONSTRAINT Language_UserTable FOREIGN KEY (fk_LanguageID)
> REFERENCES
> Language (LanguageID) ON DELETE CASCADE ON UPDATE CASCADE
> GO
>
> Please help
> ---------------
> Best regards
> - Hans -
> ---------------
Author
24 Nov 2005 5:34 AM
Hans [DiaGraphIT]
It's 6:30 AM and you've made my day :-)  Thank you
---------------
Best regards
- Hans -
---------------


Show quote
"Uri Dimant" wrote:

> Hans
> Take a look at INFORMATION_SCHEMA.TABLE_CONSTRAINTS view
>
>
> "Hans [DiaGraphIT]" <hans.ar***@sshf.no> wrote in message
> news:ABFCB48A-590E-4C05-B308-A40C67ED3C41@microsoft.com...
> > Hi!
> >
> > I want to create constraints, but I want to check if the constraint exists
> > first.  How do I do that?
> >
> > I think something like following example would work for me, but I'm not
> > sure
> > how to check... filling the space between ...exists (...)
> >
> > IF NOT EXISTS (.......)
> > ALTER TABLE UserTable
> >    ADD CONSTRAINT Language_UserTable FOREIGN KEY (fk_LanguageID)
> > REFERENCES
> > Language (LanguageID) ON DELETE CASCADE ON UPDATE CASCADE
> > GO
> >
> > Please help
> > ---------------
> > Best regards
> > - Hans -
> > ---------------
>
>
>

AddThis Social Bookmark Button