NoSQL vs. SQL Databases

Introduction In today's data-driven world, the choice of database technology plays a crucial role in shaping the efficiency and scalability of applications. Two major database types have emerged as popular choices: NoSQL and SQL databases. Each type has its strengths and weaknesses, making it essential for developers and data architects to understand when to use... Continue Reading →

Quick Reference Guide for SQL Server DBA Daily Tasks

Introduction As a SQL Server Database Administrator (DBA), daily operations can be time-consuming and require a vast amount of knowledge and experience. From managing backups to troubleshooting performance issues, a DBA's daily tasks can be daunting without a proper reference guide. That's where a cheat sheet or quick reference guide can come in handy. It... Continue Reading →

T-SQL Query To Find Deadlocks In MS SQL Server

Introduction As a Backend Developer, I have frequently encountered performance issues, particularly those stemming from poorly written code or lack of indexes, which can lead to blocking conditions called "deadlocks." These situations can directly impact user experience and become more severe with frequent occurrences. This article addresses deadlock issues and reporting. Upon completion, readers will... Continue Reading →

How To Remove Duplicate Values Without Using DISTINCT In SQL Server

Introduction Whenever we work with data, sometimes there are some possibilities of getting duplicate data, not only because of the duplicate entries but also because of the T-SQL statement. We may need to remove it as well. In this instance, most of us follow to implement the DISTINCT keyword in our T-SQL Statement. Applying DISTINCT... Continue Reading →

Find Database Owner In SQL Server

Introduction In this simple article, let's explore different ways to find a Database owner. When a database is created, generally who creates it owns it and they have all permissions on that database. The Owner can perform maintenance of the database, grant permissions to other users, and even drop the database. Different Ways to Find... Continue Reading →

How to Identify Unused Tables In SQL Server

Introduction When working on large-scale projects, we might have created many tables, or later some point we might have changed the structure as part of the requirements. There is a huge possibility of tables that are not required or unused for a long time. A good practice is to remove/delete those by identifying them. In... Continue Reading →

Find All Tables Containing Column With Specified Column Name – MS SQL Server

Introduction In this article, we will discuss how to get the list of table names that contain specific columns. Sometimes we may need to find the table names which contain similar column names or we may know the column name but, we may not remember the table name. By using a simple query we can... Continue Reading →

Where are the SQL Jobs are Stored in SQL Server

Introduction In this article, We will discuss where the SQL Jobs are stored in SQL Server. Most of us know the purpose of SQL Job, A job is a specified series of actions that SQL Server Agent performs. Use jobs to define an administrative task that can be run one or more times and monitored... Continue Reading →

How to Check SQL Server Database Size

Introduction In this simple article, I would like to share how to check DB size. Sometimes when working in a Database, we may need to know the current space occupied by that particular DB. Based on the size, we need to take action. There are three easiest ways to check it, Using T-SQL StatementUsing SP... Continue Reading →

Find When was a SQL Server View Last Modified

Introduction In this simple tips and tricks article, I would like to share how to when was a view last modified. Let's have a look at the below T-SQL Statement SELECT name as ViewName, create_date as CreatedDt, modify_date as LastModifiedDt FROM sys.views In the above T-SQL Statement list, from the column LastModifiedDt column we can... Continue Reading →

Find Table Creation Date In SQL Server

Introduction In this article, we will discuss how to get the created date of a table. Sometimes, we may need to know when the table was created in the particular database. Rather than relying on the row inserted date, we can see when the table was created. Finding the Created date using T-SQL SELECT name... Continue Reading →

List All Available Time Zone – SQL Server

Introduction In this simple tips and tricks article, I would like to share how many time zones does our SQL Server supports. Well, it's pretty much easy to find by using the system table sys.time_zone_info sys.time_zone_info Here is the sample T-SQL to get the list of time zones our SQL Server supports. SELECT name AS... Continue Reading →

To Get Total Number of Columns In a Table In SQL Server

Introduction In this simple article, lets explore to get total number of columns in a table in SQL Server Example SELECT COUNT(COLUMN_NAME) AS [Number of Columns] FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_CATALOG = 'PracticalWorks' AND TABLE_SCHEMA = 'Demo' AND TABLE_NAME = 'OrderDetails' Fig. 1 Number of Columns in a Table From the INFORMATION_SCHEMA.COLUMNS table we can find... Continue Reading →

sp_rename – Rename a column or table in MS SQL Server

Introduction In this article, I would like to share how to rename a column name or table name in SQL Server using T-SQL. For that, we have to use sp_rename. sp_rename renames the objects in the current database. Renaming column name to new column name The syntax for renaming a column in SQL Server using... Continue Reading →

Altering Column – From NULL to NOT NULL in SQL Server

Introduction When working in SQL Server tables, sometimes we may need to change a column that allows NULL to NOT NULL. This change is required as part of business requirement, that is definitely this column contains value or else as part of performance improvements, we may be in need to change the column from NULL... Continue Reading →

Execution Time of Stored Procedures In SQL Server

Introduction When working in SQL Server Stored Procedures, we are keen about the execution time of it. Its very simple to find execution time of stored procedures in SQL Server. Execution Time Its simple to figure out the execution time of stored procedures using SET STATISTICS TIME ON. SET STATISTICS TIME ON EXEC [Sales].[pGetSalesDetails] After... Continue Reading →

Different Ways To Get Table Column Names In SQL Server

Introduction In this simple article, we will discuss different ways to find the particular table's column names in SQL Server. Method One The first approach is using the system table sys.columns. This table results many columns, but we are interested only in the column name, so I am selecting name column from the sys.columns table,... Continue Reading →

Find Columns That Allows NULL In SQL Server

Introduction The columns in a table, that allows NULL in a database sometimes can lead to performance issues. The Nullable columns may be one of the reason to lead query to performance bad. By making columns NOT NULL can help the query to perform well. In this article we will discuss a simple way to... Continue Reading →

SQL Server Rank Functions

Introduction As like an Aggregate functions, the Ranking functions will rank the values of specified field and categorize them according to their rank . Ranking functions are most commonly used to find the top records based on conditions, example, to find the top ranking students, top highest paid employees and etc. Ranking Functions There are... Continue Reading →

T-SQL Query For Finding The Longest And Shortest names In A Table

Introduction In SQL Server, we can find the Longest String Value and Shortest String Value from the same table. To find the longest and shortest values, there are many ways, but in this article, we will discuss some simplest ways. Disclaimer: From this article, I am not sharing these are the only efficient ways to... Continue Reading →

MERGE Statement in SQL Server to Insert, Update, Delete Records

Introduction In a single transaction (MERGE Statement) we can perform Insert, Update and Delete records on a existing table based on the result comparison between important columns with another table. Which also means we no longer needs to write multiple T-SQL statements to handle Insert, Update, Delete. MERGE Statements To perform MERGE, we need two... Continue Reading →

One Drop Statement For Multiple Tables In SQL Server

Introduction When as a developer working in a database, which is in Development state, we may create some physical tables or temp tables to check the logic. Or based on the initial requirement we may have created more tables as part of Normalizing the data and our reviewer may suggest some better ideas to accommodate... Continue Reading →

List of Available Database for Current User In SQL Server

Introduction When working in the SQL Server, we may have to check some other databases other than the current one which we are working. In that scenario we may not be sure that does we have access to those Databases?. In this article we discuss the list of databases that are available for the current... Continue Reading →

Find Recently Modified Tables In SQL Server Database

Introduction SQL Server maintains a table to keep information about each tables that are created in appropriate databases. Its a System Table called as sys.tables. For every table created to the database, a new one record is created in the sys.tables table which contains information such as table name, object id of table, created date,... Continue Reading →

SQL Query To Increase Salary By Percentage For All Employees In A Table

Introduction Sometimes we may need to increase the current column value by Percentage. The very good example is Salary in an organization. We need to update the salary of each employee based on the Hike Percentage. Increasing Salary By Percentage In this example, lets assume the Hike percentage is equal for all employees, and I... Continue Reading →

Select Names NOT Starting And NOT Ending With Vowels in MS SQL Server

Introduction Sometime we may need to select the column results that the string not starting and not ending with Vowels. In this article, We will have a look, How to select the columns results not starting and not ending with Vowels. In our previous articles we discussed how to select columns results  Select Names Starting With... Continue Reading →

Select Names NOT Ending With Vowels in MS SQL Server

Introduction In this article, We will have a look, How to select the columns results NOT ending with Vowels. In our previous articles we discussed how to select columns results starting with vowels and column results ending with vowels. Select Names Starting With Vowels in MS SQL ServerSelect Names Ending With Vowels in MS SQL... Continue Reading →

Select Names Ending With Vowels in MS SQL Server

Introduction Sometime we may need to select the column results that the string ends with Vowels. In this article, We will have a look, How to select the columns results ending with Vowels. In one of the articles, we discussed how to select names Starting with Vowels, please refer that article here. Example As an... Continue Reading →

SQL Server String Functions

Introduction In this article, we will discuss about the SQL Server String Functions (built in functions) in SQL Server. String Functions in SQL Server ASCII() Return the ASCII code value of a character CHAR() Convert an ASCII value to a character CHARINDEX() Search for a substring inside a string starting from a specified location and... Continue Reading →

Create and Publish SQL Server Database Project With Visual Studio

Introduction Databases plays an important role in any project these days. It becomes too difficult to manage the objects such as Tables, Views, Procedures and Functions increases over the time and also difficult to manage when number of team members works in Database at the same time. And even after that when we manage the... Continue Reading →

Multiple Backup Files of the SQL Server database with SSMS and T-SQL

Introduction In this article, we will learn a simple tip to take multiple backup files of one Database. Sometime we may need more than one copy of a backup file in different file location and we can achieve that in two ways, either using T-SQL Query or using SSMS. T-SQL Statement BACKUP DATABASE [PracticalWorks] TO... Continue Reading →

Difference between CURRENT_TIMESTAMP vs GETDATE() vs SYSDATETIME() vs GETUTCDATE() in SQL Server

Introduction In this article, we will discuss the difference between CURRENT_TIMESTAMP , GETDATE() , SYSDATETIME() GETUTCDATE() in SQL Server. Even though all four SQL Server function returns the current date-time in SQL Server, there are some subtle differences between them. The main difference between GETDATE() and SYSDATETIME() is that GETDATE returns current date and time... Continue Reading →

5 Tips to Improve SQL Query Performance

Introduction In this article, I will share few SQL Tips for Boosting our SQL Query Performance. We nobody likes delay in response, right !!. Here are some simple changes that we have to make our query perform faster. The following is the flow of this write-up, Use Schema NameAlways Select ONLY required ColumnsUse NOT EXISTS... Continue Reading →

Get list of Tables & Views in MS SQL Server- sp_tables

Introduction Sometimes we may need to get all the tables and views from a database in MS SQL Server. By using T-SQL Statement sp_tables, we can retrieve a list of tables and views. Syntax sp_tables [ @table_name = 'Table name.' ] , [ @table_owner = 'The database user who created the table.' ] , [... Continue Reading →

Selecting Only EVEN or ODD Records from Tables – MS SQL SERVER

Introduction In this article, we will learn to Select only EVEN or ODD records from the MS SQL Server database table🤔. The efficient way to find the record belongs to even or odd is determining by the table's ID column. Select EVEN Records By applying the modulo operator by 2 for the ID column, we... Continue Reading →

Optimize your SQL Query – Replace Star (*) in Select Statement – MS SQL Server

Introduction Sometime we may need almost all the columns from a table result. In this scenario we use Star(*) in our select statement i.e. as SELECT * FROM TableName. Using Star(*) in the select statement is BAD. The best approach is selecting the table with column names. In this article we will learn how quickly... Continue Reading →

Backup Database using T-SQL Statements

Introduction In this article, We will discuss how to backup our database in MS-SQL Server using T-SQL Statements. We need to use BACKUP DATABASE statement to create full database backup, along with the name of Database and device to store the backup file. Syntax BACKUP DATABASE database_name TO device_name Example BACKUP DATABASE PracticalWorks TO DISK... Continue Reading →

Pinned tabs in SQL Server Management Studio (SSMS)

Introduction While working in SQL Server Management Studio (SSMS), we may need to open many query windows. But each time we may feel difficult to recognize the important query window which we need to refer frequently. There is an option, we can Pin the tabs which are mostly frequently referred. Pinning Tabs We can pin... Continue Reading →

Split Query Window in SQL Server Management Studio(SSMS)

Introduction Sometime we may write a long query in our query window and we may need to refer the objects or other part of the T-SQL frequently. For that we may be scrolling up and down in the query window. But we have an awesome option for that in the SQL Query Window, which many... Continue Reading →

Last Execution of Stored Procedure in SQL Server

Introduction In an ERP project or any other big applications, there may be many Stored Procedures used. But we are not sure that all the stored procedures are required or not or valid ones. While the requirement(s) has changed, we may ended with another new stored procedure or based on the performance we may have... Continue Reading →

List Databases Available for Current User -SQL Server

Introduction Sometimes, we may be curious to know to which databases do we have access or we need to access a particular database but not sure that we have access or not. In this article, we will discuss a T-SQL that will list the Databases available for current user. For Particular Database HAS_DBACCESS  - This... Continue Reading →

Find user who ran DROP statements – SQL Server

Introduction Sometimes we need to track or find which user has DROPPED the table(s) from the Database. In this article, we will discuss the possible ways to track this situation. I have a table already in my Database, SELECT [StudentId], [FirstName], [LastName] FROM [StudentManagementSystem].[Students].[StudentDetails] Fig 1. Results Drop table Now I am going to apply... Continue Reading →

Website Built with WordPress.com.

Up ↑