SQL SERVER – How to ALTER CONSTRAINT
After reading my earlier blog post SQL SERVER – Prevent Constraint to Allow NULL. I recently received question from user regarding how to alter the constraint. No. We cannot alter the constraint, only...
View ArticleSQL SERVER – Fix: Error: 1505 The CREATE UNIQUE INDEX statement terminated...
Here is another example where the error messages are very clear but often developers get confused with the message. I think the reason for the confusion is the word “Key” used in the error message....
View ArticleSQL SERVER – Disable All the Foreign Key Constraint in Database – Enable All...
Here is an email I received during the weekend. “Hi Pinal, I am a senior tester in the leading organization and we have two different environments 1) Testing 2) Production. As a part of the testing we...
View ArticleSQL SERVER – Create Unique Constraint on Table Column on Existing Table
Here is the question I received on twitter. “Can we create a unique constraint on table column on Existing Table?” Of course Yes! Here is how you can create a unique constraint on the table which...
View ArticleSQL SERVER – Listing Foreign Key Relationships of Table with Stored Procedure...
A very cool trick which I have previously not shared on my blog regarding how to list all the foreign key relationship of table with the help of Stored Procedure sp_fkeys. Here is a quick script how...
View ArticleSQL SERVER – Listing Primary Key of Table with Stored Procedure sp_pkeys
Here is a follow up blog post of my earlier blog post on very similar subject Listing Foreign Key Relationships of Table with Stored Procedure sp_fkeys. In previous blog post we listed foreign keys and...
View ArticleSQL SERVER – Drop All the Foreign Key Constraint in Database – Create All the...
Earlier I wrote a blog post about how to Disable and Enable all the Foreign Key Constraint in the Database. It is a very popular article. However, there are some scenarios when user needs to drop and...
View ArticleSQL SERVER – How to Disable and Enable All Constraint for Table and Database
One of the most popular questions I find still coming to via email is how to enable or disable all the constraint for single table or database. Well, in this blog post we will not discuss the reasons...
View ArticleInterview Question of Week #001 – Script to List Foreign Key Relationships...
Two years ago I wrote a book SQL Server Interview Questions and Answers with my very close friend Vinod Kumar. It is a very popular book of mine and has sold many thousands of copies so far. Every...
View ArticleSQL SERVER – Finding Tables with Primary or Foreign Keys
If you want to know if a table has a primary key or foreign key, you can find out this in many ways. Let us create these tables CREATE TABLE product_master ( prod_id INT PRIMARY KEY, prod_name...
View Article