• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 233
  • Last Modified:

I am using SQL Server's own table drop script (right click on table, script as etc).

I am using SQL Server's own table drop script (right click on table, script as etc).

When I run the drop script for a constraint, it does not drop the constraint.
0
Mr_Shaw
Asked:
Mr_Shaw
  • 2
  • 2
2 Solutions
 
Nico BontenbalCommented:
I'm not sure I understand your question. Did you use the drop table script and then replace the name of the table with the name of the constraint?

The drop constraint script would look like this:
IF  EXISTS (SELECT * FROM sys.check_constraints WHERE object_id = OBJECT_ID(N'[dbo].[constraintName]') AND parent_object_id = OBJECT_ID(N'[dbo].[tblName]'))
ALTER TABLE [dbo].[tblName] DROP CONSTRAINT [constraintName]

Open in new window


Can you provide the script that you use and that is not working?
0
 
Mr_ShawAuthor Commented:
sorry... question badly written.

The following script returns NULL.

select OBJECT_ID(N'default_value_constraint')

Therefore SQL Servers 'SCRIPT AS' script does not work....

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'default_value_constraint') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[tb1] DROP CONSTRAINT [default_value_constraint]
END

GO
0
 
Nico BontenbalCommented:
When you run:
SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'default_value_constraint') 

Open in new window

what does it return?
0
 
Mr_ShawAuthor Commented:
thanks
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now