how to disable constraint in sybase - sybase

What is the syntax to enable/disable the constraint? I tried google
in oracle I write it like this
alter table OPT DISABLE constraint FK_param
how to do that in sybase?

You simply can't disable foreign keys constraints in sybase. But you can drop and recreate
them.
Drop constraint:
alter table table_name drop constraint constraint_name
Add constraint:
alter table table_name add constraint constraint_name
I know that in other DB's, there is something like a CHECK and NOCHECK on these constraints. So you could just NOCHECK the constraint you want to disable.
ALTER TABLE a1 NOCHECK CONSTRAINT a1_TestConstraint

You can't disable constraints in sybase. You can drop/add constraints only.

Related

Cannot insert duplicate key row in object '[Reporting].[SecurityPrincipal]' due to trigger '[Reporting].[SecurityPrincipal_Insert_UniqueName]

Possible way to resolve Dynamics Ax Management Reporter issue:
Cannot insert duplicate key row in object '[Reporting].[SecurityPrincipal]' due to trigger '[Reporting].[SecurityPrincipal_Insert_UniqueName]
This could help admins with Dynamics Ax environment integrated with Management Reporter.
After successful integrations we had the error "Cannot insert duplicate key row in object '[Reporting].[SecurityPrincipal]' due to trigger '[Reporting].[SecurityPrincipal_Insert_UniqueName]", probably due to pre-existing user records.
Solution(Maybe not the best)
1. Stop Management Reporter service
2.Go to MSSQL server for ManagementReporter database and execute the following;
ALTER TABLE [Reporting].[SecurityPrincipal] NOCHECK CONSTRAINT ALL
ALTER TABLE [Reporting].[ControlColumnMaster] NOCHECK CONSTRAINT ALL
ALTER TABLE [Reporting].[ControlReportScheduleTask] NOCHECK CONSTRAINT ALL
ALTER TABLE [Reporting].[ControlReportContributorSettings] NOCHECK CONSTRAINT ALL
ALTER TABLE [Reporting].[ControlReport] NOCHECK CONSTRAINT ALL
ALTER TABLE [Reporting].[ControlReportGroups] NOCHECK CONSTRAINT ALL
ALTER TABLE [Reporting].[SecurityCompanyPermissionIntegration] NOCHECK CONSTRAINT ALL
ALTER TABLE [Reporting].[ControlRowMaster] NOCHECK CONSTRAINT ALL
ALTER TABLE [Reporting].[ControlTreeMaster] NOCHECK CONSTRAINT ALL
ALTER TABLE [Reporting].[ControlReportSchedule] NOCHECK CONSTRAINT ALL
Delete all domain user records only. Do not delete the user "Everyone" and "Management Reporter"
enter code hereDELETE FROM [ManagementReporter].[Reporting].[SecurityPrincipal] WHERE Name like 'domain%'
Re enable all constraints, start the service and hope for the table to be repopulated.
Hope this helps someone in need as I found no solutions online.

Disabling inline constraints in Visual studio table designer

It would be grand if there were a way to disable scripting inline constraints in the VS table designer. Is there a way?
The reason I'm after this behavior is that Insight.Database.Schema doesn't support inline constraints.
So instead, I'd like it to add this:
ALTER TABLE [dbo].[Users] WITH NOCHECK ADD CONSTRAINT [PK_Security_Users] PRIMARY KEY CLUSTERED
([ID])
GO
ALTER TABLE Table_Name
NOCHECK CONSTRAINT Constraint_Name
You can simply add a constraint 1st and then disable it using above statement.

Cannot drop FK Constraint

I keep getting the error when running the code below:
Cannot truncate table 'Entry' because it is being referenced by a FOREIGN KEY constraint.
--ALTER TABLE [dbo].[Entry] DROP CONSTRAINT [PK_Entry_Id]
ALTER TABLE [dbo].[Entry] DROP CONSTRAINT [DF_Entry_HideChrome]
ALTER TABLE [dbo].[Entry] DROP CONSTRAINT [DF_Entry_IsDiscussionEnabled]
ALTER TABLE [dbo].[Entry] DROP CONSTRAINT [DF_Entry_MetaDescription]
ALTER TABLE [dbo].[Entry] DROP CONSTRAINT [DF_Entry_MetaTitle]
Truncate table [Entry]
ALTER TABLE [dbo].[Entry] ADD CONSTRAINT [DF_Entry_HideChrome] DEFAULT ((0)) FOR [HideChrome]
GO
ALTER TABLE [dbo].[Entry] ADD CONSTRAINT [DF_Entry_IsDiscussionEnabled] DEFAULT ((1)) FOR [IsDiscussionEnabled]
GO
ALTER TABLE [dbo].[Entry] ADD CONSTRAINT [DF_Entry_MetaDescription] DEFAULT ('') FOR [MetaDescription]
GO
ALTER TABLE [dbo].[Entry] ADD CONSTRAINT [DF_Entry_MetaTitle] DEFAULT ('') FOR [MetaTitle]
GO
ALTER TABLE [dbo].[Entry] ADD CONSTRAINT [DF_EntryStatus] DEFAULT ('Public-Page') FOR [Status]
GO
Ok so I dropped all other constraints from any tables referencing this table but I still get one more error saying there's still a PK constraint referencing my Entry table.
I go and check out the dependencies on Entry (view dependencies) and see that the comment table is still dependent on it:
Then I see there's a FK as one of the main fields of the comment table but you can't drop that I guess.
So I don't see what other dependencies are referencing this Entry table when View Dependencies says the only table left after I dropped constraints on the other tables is from the Comment table? I don't see it.
In the code of dropping the constraint that you have provide you are not dropping the DF_EntryStatus key. You have only dropped these 4 keys.
ALTER TABLE [dbo].[Entry] DROP CONSTRAINT [DF_Entry_HideChrome]
ALTER TABLE [dbo].[Entry] DROP CONSTRAINT [DF_Entry_IsDiscussionEnabled]
ALTER TABLE [dbo].[Entry] DROP CONSTRAINT [DF_Entry_MetaDescription]
ALTER TABLE [dbo].[Entry] DROP CONSTRAINT [DF_Entry_MetaTitle]
As this DF_EntryStatus still referencing you are not able to truncate the table.
Hope this solves our problem.
For some odd reason, I had to drop the key FK_Comment_Comment. Don't know how it's related to the Entry table though...weird.

How to recheck primary/foreign key constraint for data already in the table in sql server?

I have a table in SQL Server 2005 with a foreign key and it was disable for huge data loading, and then re-enabled:
Example:
alter table table1 nocheck constraint fk_1
go
lots of inserts...
go
alter table table1 check constraint fk_1
go
Now, the question: is there a way to re-check this just inserted data?
The syntax looks a little silly with the word "check" repeated, but what you want is:
alter table table1 with check check constraint fk_1
go
Adding the "with check" option will validate existing data against the constraint. Doing this will also prevent the constraint from becoming untrusted.
If any existing data violates the constraint, you'll get an error that will look like this:
The ALTER TABLE statement conflicted with the CHECK constraint "fk_1".

How to drop tables with no constraint checking

I need to update the data and schema from dev to staging dbs where I want to DROP/CREATE a group of tables. I need to over-ride the FK constraint checks. Looking at the MS's ALTER TABLE syntax tree - i know it's there but i can't identify the correct syntax.
#Rup: It looks like the hangup is from other tables' FKs. Is there a way to turn all constraint checking off or do i need to produce the list of tables/FKs?
ALTER TABLE yourtable
NOCHECK CONSTRAINT ALL
and a variation on this theme is to disable all the constraints of all the tables delete all the data, and then add all the constraints back again.
exec sp_MSforeachtable #command1='alter table ? nocheck constraint all', #whereand='and substring(o.name,1,1) <> ''_'''
exec sp_MSforeachtable #command1='delete from ?'
exec sp_MSforeachtable #command1='alter table ? check constraint all', #whereand='and substring(o.name,1,1)<> ''_'''
The nice thing here is that with all the constraints disabled, you can delete the data in any order
You can drop the constraints, drop the tables and re-create. It should also be possible to drop the tables in the correct order and re-create if there are no circular constraints.
ALTER TABLE DROP CONSTRAINT

Resources