Quantcast
Channel: Scripts – SqlHints.com
Browsing all 28 articles
Browse latest View live

Index misuse Script

Below Script can be used to create a database PerformanceTraining with a table Employee. This script populates 5 Lakh records in the employee table. Note: Copy paste of this script is not working...

View Article


Image may be NSFW.
Clik here to view.

How to find all the Stored Procedures having a given text in it?

Recently, I was needed to search for all the Stored Procedures having a given text in its definition. So, as usual did the g gling,  most of the top results returned were suggesting to use...

View Article


How to Calculate Age in Sql Server

Recently, while filling some form needed to provide my age in years. Thought of calculating it in sql server and as usual used the DATEDIFF function like below, but it gave me wrong answer: Script...

View Article

Image may be NSFW.
Clik here to view.

How to find all tables that have specified column name in Sql Server?

We can use a script like below to find all the tables in the database that have column with specified name in it: SELECT SCHEMA_NAME(schema_id) + '.' + t.name AS 'Table Name' FROM sys.tables t...

View Article

Image may be NSFW.
Clik here to view.

How to get Quarter’s Start and End Date for a given date in Sql Server

We can use a query like below to get Quarter’s Start and End Date for a given date. DECLARE @AnyDate DATETIME SET @AnyDate = GETDATE() SELECT @AnyDate AS 'Input Date', DATEADD(q, DATEDIFF(q, 0,...

View Article


Image may be NSFW.
Clik here to view.

How to find all the indexes that have included columns in it and the name of...

We can write a query like below to get the name of all the indexes that have included columns in it and the name of the table to which the index belongs to: SELECT DISTINCT T.Name 'Table Name', I.Name...

View Article

Image may be NSFW.
Clik here to view.

How to find all the filtered indexes or all the tables having filtered...

We can write a query like below to get the name of all the filtered indexes or all the tables having filtered indexes in Sql Server: SELECT DISTINCT T.Name 'Table Name', I.Name 'Filtered Index Name',...

View Article

Image may be NSFW.
Clik here to view.

How to get all HEAP Tables or Tables without Clustered Index in Sql Server?

A Table that doesn’t have a Clustered Index is referred to as a HEAP Table. We can write a query like below to get all the HEAP Tables or tables that doesn’t have Clustered Index: SELECT T.Name 'HEAP...

View Article


Image may be NSFW.
Clik here to view.

How to get all the Tables with or without Primary Key Constraint in Sql Server?

We can write a query like below to get all the Tables with no Primary key constraint: SELECT T.name 'Table without Primary Key' FROM SYS.Tables T WHERE OBJECTPROPERTY(object_id,'TableHasPrimaryKey') =...

View Article


Image may be NSFW.
Clik here to view.

How to find all the tables with no indexes at all in Sql Server?

We can write a query like below to get all the Tables in the Database that don’t have any indexes: SELECT Name 'Tables without any Indexes' FROM SYS.tables WHERE...

View Article

Image may be NSFW.
Clik here to view.

How to get all the Tables with or without Non-Clustered Indexes in Sql Server?

We can write a query like below to get all the Tables without any Non-Clustered indexes: --List all the Tables with NO Non-Clustered Indexes SELECT Name 'Tables without any Non-Clustered Indexes' FROM...

View Article

Image may be NSFW.
Clik here to view.

Joining Two Tables without any Common Column between them – Sql Server

A friend of mine was needed a script where he wanted a One-to-One record mapping between two tables records which don’t have any common column between them for joining. That is he wanted to match the...

View Article

Image may be NSFW.
Clik here to view.

How to get all the records which contain double byte data or all the records...

In NVARchar DataType column we can store both Single byte and Double byte data. Many a times we want to know how many records have Single byte or Double byte data. Let us understand this with an...

View Article


How to get All the Tables which are Modified in last few days in Sql Server?

We can write a query like below to get the all the Tables which are modified using an ALTER statement in last 10 days. A Table is also considered as modified when an Index on the table is Created or...

View Article

Image may be NSFW.
Clik here to view.

How to Check if a String Contains a Substring in it in Sql Server

We can use the CHARINDEX() function to check whether a String contains a Substring in it. Name of this function is little confusing as name sounds something to do with character, but it basically...

View Article


Image may be NSFW.
Clik here to view.

PRINT/SELECT Statement messages within WHILE LOOP or BATCH of statement is...

Are you facing the problem where the PRINT/SELECT statements messages are not being displayed like the one’s explained in the below two scenario’s? Let us go through these scenario’s and also see how...

View Article

Image may be NSFW.
Clik here to view.

How to get Quarterly Data in Sql Server

This article demonstrate how to get quarterly data in Sql Server in different formats as shown in the below image. Here Sales table data is presented in two different quarterly aggregated sales data...

View Article


Image may be NSFW.
Clik here to view.

How to get Monthly Data in Sql Server

This article demonstrate how to get Monthly data in Sql Server in different formats as shown in the below image. Here Sales table data is presented in two different Monthly aggregated sales data...

View Article

Image may be NSFW.
Clik here to view.

SINGLE_USER, RESTRICTED_USER and MULTI_USER user access modes in SQL SERVER

In this article let us go over the following aspects of the database user access modes: What are the different database user access modes and their meanings? How to SET database to different user...

View Article

Image may be NSFW.
Clik here to view.

How to check if Temp table exists in Sql Server?

This article shows how in Sql Server we can check the existence of Temporary Table. To demonstrate this let us first create a Temporary Table with name #TempTable. --Create Temporary Table CREATE TABLE...

View Article
Browsing all 28 articles
Browse latest View live