Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesWhat is wrong with IF object_id sql in DNN format?What is wrong with IF object_id sql in DNN format?
Previous
 
Next
New Post
2/10/2015 1:46 PM
 

What is wrong with IF object_id sql in DNN format?

IF object_id(N'{databaseOwner}{objectQualifier}IX_swiztype'), 'C') IS NOT NULL)

BEGIN

ALTER TABLE {databaseOwner}{objectQualifier}swiztype ADD CONSTRAINT

       IX_swiztype PRIMARY KEY CLUSTERED

       (

       TypeID

       ) ON [PRIMARY]

END

GO


Above sql when add extension on the second pass (has IX_swiztype) it throws the below error

SQL Execution resulted in following Exceptions: System.Data.SqlClient.SqlException (0x80131904): There is already an object named 'IX_swiztype' in the database. Could not create constraint or index.

IF (OBJECT_ID('IX_swiztype', 'C') IS NOT NULL)

BEGIN

ALTER TABLE dbo.swiztype ADD CONSTRAINT

       IX_swiztype UNIQUE NONCLUSTERED

       (

       TypeName

       ) ON [PRIMARY]

END

GO

 

Above sql run direct is OK 

Command(s) completed successfully.


C = CHECK constraint is from http://stackoverflow.com/questions/482885/how-do-i-drop-a-foreign-key-constraint-only-if-it-exists-in-sql-server
 
New Post
2/10/2015 6:19 PM
 

your alter is incorrect - you check for one index name but missed the databaseowner/objectqualifier piece when adding it

IF object_id(N'{databaseOwner}{objectQualifier}IX_swiztype'), 'C') IS NOT NULL)


BEGIN

ALTER TABLE {databaseOwner}{objectQualifier}swiztype ADD CONSTRAINT

       {databaseOwner}{objectQualifier}IX_swiztype PRIMARY KEY CLUSTERED

       (

       TypeID

       ) ON [PRIMARY]

END

GO

Buy the new Professional DNN7: Open Source .NET CMS Platform book Amazon US
 
New Post
2/10/2015 7:07 PM
 
 
New Post
2/10/2015 7:13 PM
 
Lee, please note that an Index is not a constraint - the object might exist, but be an index and not a constraint.
See my Turbo scripts for samples how deal with it.

Cheers from Germany,
Sebastian Leupold

dnnWerk - The DotNetNuke Experts   German Spoken DotNetNuke User Group

Speed up your DNN Websites with TurboDNN
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesWhat is wrong with IF object_id sql in DNN format?What is wrong with IF object_id sql in DNN format?


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out