Tag: database
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…
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…
How to ALTER a Column from Null to NOT Null in SQL Server ?
Assume a scenario where you have a table that contains columns which are Nullable integer column. You might want to update them to NOT NULL column (adding NOT NULL constraint) and set its value to zero. How to ALTER a Column from Null to NOT Null in SQL Server ? This would be a two step process where you should first update the column values…
Inner Join in SQL Server
You can use inner join to get the result of two tables that match the criteria. For example , assume that you have a Person table and a Phone Number table where every person would have 0 or more phone number associated to him and you wish to get the person records who have at least one phone number. Here’s the query on how to…
Sleep Command in SQL Server
If you are looking at writing a query to sleep for or WAIT for a certain amount of time before the query execution can begin , you can use the WAITFOR command. For example , if you want to wait for 1 minute , the query or command for the same will be this.
Specify a port number when connecting to SQL Server in Management Studio
There are times when you want to connect to a SQL Server instance that is running on a different port number than default port (1433). How to specify a port number when connecting to a SQL Server instance in SQL Management Studio ? Just specify the SQL Server instance that you are connecting to along with the port number with comma as delimiter. For example…
How to get the list of all tables from a SQL Server database ?
If you need to get the list of all tables from a SQL Server database , you can query the information_schema.tables by specifying the TABLE_TYPE parameter search criteria to “BASE TABLE’. How to get the list of all tables from a SQL Server database ?
Top Database Visualization Tools for Database Developers
There are plenty of databases available which includes SQL Server, Oracle, and MySQL etc. The developers would sometimes want to understand the scheme or the database structures etc. What are the different database visualization tools available for the developers? In this article, we list out some of the database visualization tools for database developers. Some of them are free and some are commercial products. Database…
Sorting the Data in a Query in SQL Server
You want the results of the query to be displayed in a sorted order based on some query. In this case , you use the ORDER BY clause in the query by specifying the column on which the sort to work. For example , you want to sort the Departments table in the database by the column DepartmentName. Here’s how the query looks like This…
How do you check if an index exists in a table?
You can find out if the index exists for a table by querying the sys.indexes table as shown in this blog post’s code sample. How do you check if an index exists in a table? This will list out all the indexes of the table.
How to Declare a variable in SQL Server ?
You will most likely declare a variable in the SQL Server and use it in the SQL Statements. You can use the DECLARE statement and specify the variable and datatype and optionally provide a default value. For example , You can declare an NewEmployeeJobTitle variable using the DECLARE statement and provide a default value as ‘Chief Executive Officer’ DECLARE @NewEmployeeJobTitle nvarchar(50) = ‘Chief Executive Officer’;…
How to Check if a login exists in SQL Server ?
If you need to check if a login exists in SQL Server , you can use query the master.dbo.syslogins for it. How to Check if a login exists in SQL Server ? Here’s a sample query demonstrating how you can query master.dbo.syslogins to find out if the login exists in SQL Server. This would retreive all the details of the loginid ‘sa’.