Remove SCHEMABINDING from a View in SQL Server

The purpose of schema binding a view is to ensure that the base tables referenced in the view cannot be modified in a way that would affect the view definition.

This is normally a good thing. After all, you don’t want someone coming along and dropping a table that your view depends on, do you?

But what if you need to make changes to one or more tables referenced by your view?

Continue reading

Create a Temporary Table in SQL Server

In SQL Server, temporary tables are created using the same CREATE TABLE syntax as regular tables. The difference is that temporary tables’ names are prefixed with either one or two number signs (#), depending on whether it’s a local temporary table or global temporary table:

  • Local temporary tables are prefixed with a single number sign (#)
  • Global temporary tables are prefixed with a double number sign (##)

Continue reading

What is @@SERVICENAME in SQL Server?

In SQL Server, the @@SERVICENAME configuration function returns the name of the registry key under which SQL Server is running.

No argument is required. You can simply use it in a SELECT statement to return the registry key’s name.

Note that SQL Server runs as a service named MSSQLServer. The @@SERVICENAME function returns MSSQLSERVER if the current instance is the default instance. It returns the instance name if the current instance is a named instance.

Continue reading