SQL

  • SQL Server Vs Postgre SQL

    SQL Server vs PostgreSQL – Which One Should You Use?

    .

    Introduction Choosing the right database is one of the most important decisions when building an application. A good database improves performance, security, and scalability. Two popular database systems are Microsoft SQL Server and PostgreSQL. Many developers and companies compare these two databases when designing modern applications. Both are powerful relational database management systems (RDBMS). Both…

  • Types of Databases

    Types of Databases and Their Compatible Technologies

    .

    Modern applications depend on databases to store, manage, and retrieve data efficiently. From social media platforms to banking systems, every software application uses a database in some form. However, not all databases work the same way. Different databases are designed for different purposes, technologies, and workloads. In this article, we will explore the major types…

  • 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 functions. Some of the aggregate functions are Count(), Sum(), Max(), Min(), AVG() Group By Clause…

  • 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 machines. Since the arrival of the SQL Server’s first version, the SQL server has continued…

  • 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 two or more resources are trying to access the same resource which is mutually being…

  • 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 Name like this – If the Employee Name is unique then select it and if…

  • ,

    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 is a lightweight computer data interchange format.We can use JSON data in SQL Server tables…

  • 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 called from another SQL Statement.3) Stored Procedures are precompiled. Functions are not precompiled.4) Generally Stored procedures are…

  • 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    INSERT INTO [users] (uid,first_name,last_name,email,password,gender,is_active,reg_date) VALUES (NEWID(),@fname,@lname,@email,@password,@gender,1,GETDATE())ENDStored procedure to return id of last inserted record:@id int…

  • 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 key.If a table has userid, email, passport no. and userid is the primary key then how to maintain the…

  • 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’ select * from [ServerName].[DBName].[DBO].[TableName] Once your requirement is done, you may drop the linking by…

  • 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 above SPs successfully, you can check linked server list by executing below SP. exec sp_linkedservers

  • 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 properties please ensure that “Relocate all files to folder” is checked. Try this, i resolved…

  • 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 AS UID + RIGHT(00000000 + CAST(ID AS VARCHAR(8)), 8) PERSISTED,   username varchar(200),city varchar(200)  )

  • 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]”;        string exceldataQuery = “select [id],[email],[status] from [Sheet1$]”;        try   …


RSS
YouTube
YouTube
Instagram