Tag: SQL Server
How to drop a table if it exists in SQL Server 2014 ?
Assume that you want to write a SQL Query in SQL Server which checks if the table exists in database and want to drop it , you can use the OBJECT_ID function to determine the table existence by passing the table name and the ‘U’ as parameters. How to drop a table if it exists in SQL Server 2014 ?
How to get the first character of a string in SQL Server ?
Assume a scenario where you have a column in your table in SQL Server database where you want to retreive the first character of the column value. How to get the first character of a string in SQL Server ? You can use the LEFT function and specify the column name as well as the number of characters from left that you want to retreive.
Checking the version of a SQL Server using T-SQL
There are couple of ways in which you can retreive the version of the SQL Server using T-SQL. Checking the version of a SQL Server using T-SQL 1. using @@VERSION 2. Using SERVERPROPERTY function as shown
How to get the date part from the date time in SQL Server ?
If you are on SQL Server 2008 and higher version and want to get the date part of the datetime data in SQL Server , you can use the CONVERT method as shown in this post. How to get the date part from the date time in SQL Server ? If you want to get the current date leaving out the time from the datetime…
SQL Server 2014 Tutorial – Install SQL Server 2014 on Windows 10 machine
Problem Statement You need to install SQL Server 2014 Express edition on Windows 10 machine. Solution There are several ways in which you can install SQL Server. These includes options via command prompt, unattended, server core etc. In this tutorial, we will explore the simplest method using the SQL Server 2014 Setup wizard. Follow the below steps to install SQL Server 2014 1. Download SQL…
SQL Server 2014 Tutorial – List all the databases in SQL Server using Query
Problem Statement You need to list all the databases that are present in the current SQL Server instance. Solution The list of all the databases from the SQL Server instance can be obtained from the sys.databases object as shown below. 1. Open SQL Management Studio and connect to the SQL Server instance with your login details. 2. Click the “New Query” button and enter the…
SQL Server 2014 Tutorial – Manage SQL Server services
Problem Statement You need to manage the SQL Server services that are installed on your server machine. Solution Use SQL Server Configuration Manager tool to manage the SQL Server services on your machine. Following are some of the actions that you can perform using the SQL Server Configuration Manager – Start , Stop , Pause , Restart a SQL Server Service – Modify or configure…
Column Alias in SQL Query
When returning the query results , you want to provide an alternate name for the column for readability purpose , you can use the AS clause to specify the column alias in SQL Query. How to specify Column alias in SQL Query ? Below is an example of the usage of the column alias in SQL Query. Every column in the Query result has a…
How to get the first day of the month in SQL Server ?
If you want to get the first day of the month of a input datetime variable from a SQL Query , here’s how you do it.
Exit the Current Scope with a return value in SQL Server
You can use the RETURN statement to discontinue the execution of a T-SQL batch statement or a stored procedure and provide a status code or value on return. For example , you want to display the Employees whose MaritalStatus is Divorced. You want to return a value -1 to indicate that no records exist and also You do not want the SQL Statements following it…
How to escape a single quote in SQL Server ?
You can escape a single quote in your T-SQL query in SQL Server by simply doubling them. Here’s a simple example that demonstrates how the single quote ie escaped in SQL Server. How to escape a single quote in SQL Server ?
What is the equivalent of MySQL’s Now() function in SQL Server ?
MySQL has the function Now() which is a Datetime type field which shows the current date as well as the time. What is the equivalent of MySQL’s Now() function in SQL Server ? In SQL Server , you can use the GetDate() function to achieve the same.