logo
search
Others

How to Change the Schema of a Schemabound SQL Server Function

Kushani NimanthikaKushani Nimanthika Sep 27, 2026 869 views

Question details

The user needs to modify or transfer the schema of a scalar-valued function in SQL Server that is currently protected by schema binding.

How to Change the Schema of a Schemabound SQL Server Function
Product
SQL Server
Device & OS
not provided
Scenario
Attempting to transfer a database object to a new schema using the ALTER SCHEMA command.
Observed behavior
The schema change command fails and returns an error because SQL Server does not permit direct transfers of objects created with the WITH SCHEMABINDING option.
Before you start

Before altering any database schema, ensure you have scripted out the exact definition of the affected schemabound function and verified its dependencies.

Solution 1Recommended

Remove Schemabinding and Recreate the Function

To move a schemabound function to a new schema, you must temporarily remove the schemabinding, transfer the object, and then reapply the binding.

SQL Server enforces strict dependency checks on objects created with SCHEMABINDING. You cannot use the standard ALTER SCHEMA TRANSFER command directly on these objects. The safest approach is to alter the function to remove the binding before the transfer.

1
Script out the function

In SQL Server Management Studio (SSMS), locate the scalar-valued function, right-click it, select 'Script Function as', and choose 'ALTER To' in a New Query Editor Window.

2
Remove the SCHEMABINDING clause

In the generated script, locate the 'WITH SCHEMABINDING' clause and delete or comment it out. Execute the script to update the function.

3
Transfer the schema

Open a new query window and execute the transfer command: ALTER SCHEMA [NewSchema] TRANSFER [OldSchema].[YourFunctionName];

4
Reapply SCHEMABINDING

Update your ALTER script to reflect the [NewSchema] name, add the 'WITH SCHEMABINDING' clause back into the definition, and execute the script to restore dependency protection.

Remove Schemabinding and Recreate the Function
Dependency Warning: If the function is heavily referenced by other schemabound views or functions, you will need to temporarily drop or alter those dependent objects in a cascading manner before making this change.
Free Microsoft Office alternative

Document Your Database Schemas Seamlessly with WPS Office

While you manage complex SQL Server dependencies, WPS Office provides a lightweight, highly compatible suite to document your queries, create schema transfer plans, and collaborate on database administration tasks.

  1. 1. Download WPS Office: Visit the official WPS website and download the free installation package for your operating system.
  2. 2. Create database documentation: Open WPS Writer and start a new document to keep track of your schema changes, SQL scripts, and deployment plans.
  3. 3. Save and share: Save your documentation in standard .docx format to easily share it with other database administrators or team members.
Fully compatible with Microsoft Word, Excel, and PowerPoint file formats.Easily format, highlight, and document complex SQL query scripts in WPS Writer.Lightweight architecture ensures fast loading, even when running heavy database management tools alongside.Free to use with a familiar, easy-to-navigate tabbed interface.
microsoft office alternative - wps office

Frequently Asked Questions

What is the purpose of SCHEMABINDING in SQL Server?

SCHEMABINDING binds a function or view to the schema of the underlying base tables. It prevents those base tables from being altered or dropped in a way that would break the function, ensuring database integrity.

Why does ALTER SCHEMA fail on schemabound objects?

SQL Server prevents moving a schemabound object to a different schema because doing so could silently break the strict dependencies locked in by the SCHEMABINDING declaration. The binding must be explicitly removed before any structural move occurs.

How do I find all schemabound functions in my database?

You can query the sys.sql_modules catalog view in SQL Server by filtering for is_schema_bound = 1. Joining this with sys.objects will list all functions, procedures, and views that utilize schema binding.