SQL
SQL Server – Group by and Group by Rollup
.
In this article, we will see Group By and Group By Rollup in SQL Server. Group By The GROUP BY clause in the SQL server groups rows with the same values into summary rows. Group By is used with aggregate…
Mastering SQL Server: Essential Tips for Beginners
.
In this article, We will cover all the topics of SQL Server. This will work as SQL Server notes for beginners. SQL Server is a relational database management framework created by Microsoft. It is profoundly adaptable and runs on Windows-based…
Trace and Detect a Deadlock with SQL Server Profiler
.
In this article, we will see about deadlocks in SQL and how to trace and detect a deadlock with SQL Server Profiler. Let’s start with an introduction to Deadlock. What is Deadlock? Deadlock in SQL server is a scenario where…
How do you remove duplicate records with different status in SQL Server?
.
In this article, I will explain a scenario where the user has to remove duplicate records with different statuses. Scenario Consider below the table with 2 columns (Employee Name and Status) Now, write a query to fetch a unique Employee…
JSON functions and examples in SQL Server
.
In this blog, we will see the use of JSON functions and examples in SQL Server. We will also see how to query and modify JSON data using SQL Server Query.As you already know JSON stands for JavaScript Object Notation, which…
Differences between Stored Procedure and Functions
.
Very frequent question asked in interview is Differences between Stored Procedure and Functions.Below are the differences between these 2. 1) Functions must return a value. Stored procedure need not be.2) Stored procedures can be called using EXEC command where as Functions can be…
Important SQL Query asked in Interview
.
Important SQL Query asked in InterviewSQL query to check a record in table, if exist then insert else update the record. BEGIN IF EXISTS (SELECT * FROM [users] WHERE email=@email) UPDATE [users] SET updated_date = GETDATE() WHERE email=@emailELSE …
SQL Server Interview Questions.
.
In this blog, we will see some of the important SQL Interview Questions and Answers. 1. What is a Primary Key? The primary key is used to uniquely identify a record. A table can not have more than one primary…
All about sp_addlinkedserver syntax
.
sp_addlinkedserver linked 2 servers. Once sp_addlinkedserver query executes, query can be run against these servers. Run below queries one by one to link, to provide login credentials and to access data EXEC sp_addlinkedserver @server=’ServerName’ EXEC sp_addlinkedsrvlogin ‘ServerName‘, ‘false’, NULL, ‘username’, ‘password’…
How to link 2 SQL DB servers
.
If someone wants to get data from 2 tables from 2 different SQL DB server. Then execute below stored procedures before running your query. Step1: exec sp_addlinkedserver @server=db-server-name Step2: EXEC sp_addlinkedsrvlogin db-server-name, false, NULL, id, password Once you executed…
Error while restoring sql database in microsoft sql server 2012
.
I found below error while restoring a database to Microsoft SQL Server 2012.System.Data.SqlClient.SqlError: The operating system returned the error 5(Access is denied.) I solved this problem by doing below step:In restore window, from left side pane click on FilesThen in…
How to automatically generate unique id in sql?
.
In sql there are many options to generate unique number. Here I am explaining about how to generate standard unique number in sql. Below is sql query : CREATE TABLE dbo.tblTable1 (ID INT IDENTITY(1,1) NOT NULL PRIMARY KEY CLUSTERED, UserID…
Bulk copy data from excel sheet to sql table
.
How to process bulk copy data from excel sheet to sql table. Here is code to copy data from excel to sql. C# Code: string excelFile = @”C:Book1.xls”; string ssqlTable = “[MyTableName]”; …
