As an independent database consultant, I often face a challenge when analyzing the performance of SQL Server instances, which I see for the first time in my life. In many cases, this may seem a difficult task, because in order to fix something you must first understand the database structure. A great many of the companies do not document their database. And even if documentation exists, it is rarely updated. As a result, we have the following situation – documentation is either obsolete, or does not reflect the actual state of things. Let understand SQL SERVER – View Dependencies.
SQL 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 VARCHAR(100), price DECIMAL(12,2) ) GO CREATE TABLE product_details ( prod_id INT, sales_date DATETIME,…
Read MoreInterview Question of the Week #001 – Script to List Foreign Key Relationships and Constraint Name
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 single day I still get quite a many different interview questions in…
Read MoreSQL 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 why do you need them or what are the advantages or disadvantages…
Read MoreSQL SERVER – Drop All the Foreign Key Constraint in Database – Create All the Foreign Key Constraint in Database
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 recreate the foreign constraints. Here is a fantastic blog comment by SQL Expert…
Read MoreSQL 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 now we will list the primary key of the table with the help of Stored…
Read MoreSQL SERVER – Listing Foreign Key Relationships of Table with Stored Procedure sp_fkeys
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 you can use stored procedure sp_fkeys to list all the foreign key relationship.…
Read More