Tag: SQL Server

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”…

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…