Category Archives: Notes

All Articles

Prevent Truncation of Dynamically Generated Results in SQL Server Management Studio

Problem
While working with the Results to Text option in SSMS, you may come across a situation where the output from dynamically generated data is truncated. In this article I will guide you on how to fix this issue and print all the text for the Results to Text option.

Solution
http://www.mssqltips.com/sqlservertip/2795/prevent-truncation-of-dynamically-generated-results-in-sql-server-management-studio/

Steps to Check the Host Name for a Clustered SQL Server Instance

Problem
While troubleshooting a SQL Server cluster failover issue, it is essential to know the time needed for the cluster failover and the node name where SQL Server was running before the failover occurred. In this tip, I will show you the different options to find the failover time and node name where SQL Server was running before the failover over.

Solution
http://www.mssqltips.com/sqlservertip/2744/steps-to-check-the-host-name-for-a-clustered-sql-server-instance/

Error: Database diagram support objects cannot be installed

There will be situation while creating the database diagram, you got the below error message.

Database diagram support objects cannot be installed because this database does not have a valid owner. To continue, first use the Files page of the Database Properties dialog box or the ALTER AUTHORIZATION statement to set the database owner to a valid login, then add the database diagram support objects.

Above error is self explanatory where it is stating that the “set the database owner to valid login” To fix the issue please follow below one of the solution.

Solution 1:
Execute the below script by mentioning the database name.

ALTER AUTHORIZATION ON DATABASE::MentionDatabaseName TO sa
GO

OR, you can change the owner by executing the below query.

EXEC sp_changedbowner 'sa'

Solution 2:
Right Click on the database -> Database Properties -> click on files page -> change the owner to SA

T-SQL Script to identify tables without Primary Key

When designing tables, It is a good practice of having one column that is unique and can be a primary key. You can include one of the below type column as Primary Key

– Add Auto Increment Column
– Identify the column which unique for all the rows

Make sure Primary keys should be as small as necessary. Prefer a numeric data type because numeric types are stored in a much more compact format than character formats. Most primary keys will be foreign keys in another table as well as used in multiple indexes. The smaller your key, the smaller the index, the less pages in the cache.

You can execute below script to identify the tables without Primary Key and add the Primary Key into tables as per the above suggestions..


Use <Database Name>

SELECT SCHEMA_NAME(schema_id) AS [Schema Name], name AS [Table Name]
FROM sys.tables
WHERE OBJECTPROPERTY(OBJECT_ID,'TableHasPrimaryKey') = 0
Order by name
GO