Tag: SQL Server
UPDATE from SELECT query in SQL Server
Assume a scenario where you have a temporary table contains the data and would like to update a table using the values from the temporary table. Here’s an query demonstrating how to do it in SQL Server.
How to display Row Numbers in the results in SQL Query ?
If you want to return the row number as a part of your results in the SQL Query , you can use the ROW_NUMBER function and specify the ORDER BY clause to it as shown in this blog post. How to display Row Numbers in the results in SQL Query ?
How to Add a Column with Default Value to Existing Table in SQL Server ?
Looking to add a column with default value to an existing table in SQL Server ? Below is an example and sample Data Definition Language Query for achieving the same. How to Add a Column with Default Value to Existing Table in SQL Server ? Assume that the table name is “ACEmployee” which already exists and you want to add a new column called “Status”…
SQL Server 2014 Tutorial – Open SQL Server Instance Port in Windows Firewall
Problem Statement You need open the SQL Server Instance port number in Windows Firewall so that you can connect to SQL Server from another machine. Solution When you try to connect to the SQL Server instance from another machine , you might receive the connection timeout error . To allow the users of other machine to connect to your SQL Server instance , you need…
Getting all the Foreign Key constraints list of a table in SQL Server
You might need to write a T-SQL Query to retrieve all the foreign key constraints of a given table in SQL Server. For these cases , you can use the sp_fkeys stored procedure. How to get all the Foreign Key constraints list of a table in SQL Server ?
How to Get a value to a Variable in SQL Server ?
When you use the declare a variable using the DECLARE statement. The same variable can be used to store a value retrieved from the database and later can be used in your SQL Query. How to Get a value to a Variable in SQL Server ? For example , you want to retreive the value of the column JobTitle and store it in the variable…
How to return the SHA1 hash value of a string in SQL Server ?
SQL Server provides a function HashBytes function that returns the SHA1 , MD2 , MD4 and few other hash value of the specified input. How to return the SHA1 hash value of a string in SQL Server ? Just pass the ‘SHA1’ as the first parameter and the input as second parameter value to the HashBytes function to get the SHA1 hash value.
How to Check if the table exists in SQL Server ?
Do you want to know if the table exists in a in SQL Server ? . Below is a sample query that lets you know if the table exists or not. How to Check if the table exists in SQL Server ? Assume that the table name is Employee , run the below query to know if the table exists in the SQL Server or…
SQL Server – Saving changes is not permitted. The changes you have made require the following tables to be dropped...
There are times when you get an error stating “Saving changes is not permitted. The changes you have made require the following tables to be dropped and re-created. You have either made changes to a table that can’t be re-created or enabled the option Prevent saving changes that require the table to be re-created.” You can easily resolve this issue by following the steps mentioned…
How to Enable All Constraints back in the Database in SQL Server ?
In one of the articles , we explained How to Disable All Constraints in the Database temporarily in SQL Server ? , let’s look at the option of how to enable back the constraints in the SQL Server Database. How to Enable All Constraints back in the Database in SQL Server ? Below is a sample query that enables all the constraints back to the…
using IN clause to provide a list of values for Search Criteria
In SQL Server , you can use the IN clause to providing the list of values for a search criteria. For example , you want to display the employee records who’s job title is one of the following : ‘Design Engineer’,’Tool Designer’. The above query uses the IN clause to filter the employee records using the arbitrary list of values. Alternatively , you can also…
Exit the Current Scope without returning a value in SQL Server
You can use the RETURN statement to discontinue the execution of a the T-SQL batch statement. For example , you want to display the Employees whose MaritalStatus is Divorced. You donot want the SQL Statements following it to be executed if this condition doesn’t match. You can use the IF NOT EXISTS and use the RETURN statement as shown in this example. The second statement…