SQL Server BasicsWhat is SQL Server database?What is RDBMS?What is Normalization?Why we use Denormalization?What_is_SQL?What is PL/SQL?Difference between SQL and PL/SQLDatabase TableOne to One RelationshipOne to Many RelationshipMany to Many RelationshipMany to One RelationshipString Data TypesNumber Data TypesDate Data TypesOther Data TypesCreate DatabaseDrop DatabaseCreating and Managing Users in SQL ServerCreate TableAlter TableDrop TableConstraints in SQL serverPrimary KeyForeign KeyUnique KeyCandidate KeyComposite KeyDifference between primary key and candidate keyPrimary key and foreign key relationshipSurrogate KeyCascading Referential Integrity ConstraintsSelf Referential Integrity ConstraintsInsert into statementInsert multiple recordsUpdate statementDelete statementTruncate statementDifference between Delete and TruncateAlias in SQL ServerSelect statementSelect DistinctSelect TopSelect IntoNull Functions(ISNULL(),NULLIF(),COALESCE())Sub QueryIdentity ColumnSequence objectDifference between sequence and identity columnSQL Server ClausesWHERE ClauseOrder By ClauseTop N ClauseGroup By ClauseHaving ClauseDifference between Where and HavingSQL Server OperatorsArithmetic OperatorsComparison OperatorsLogical OperatorsBitwise OperatorsAny OperatorsAll OperatorsUnion OperatorsUnion All OperatorsDifference between Union and Union AllIntersect OperatorExcept OperatorDifference between Except and IntersectJoinsInner JoinLeft JoinRight JoinFull JoinSelf JoinCross JoinViewsWhat are views?Create views using SSMSIndexed ViewsComplex ViewsCheck Option in ViewCheck Encryption in ViewSchema Binding Option in ViewRead-only ViewsUpdatable ViewsAdvantages and disadvantages of viewsCreate multiple views on one tableCan we implement index on views?Can we Perform Insert, update, delete operation on views?Stored Procedure and FunctionsWhat are Stored Procedures?Why we use stored procedures?Passing parameters to Stored procedureUser-Defined FunctionsDifference between UDF and Stored procedurePre-Defined Functions@@Indentity and Scope_IndentityNULLIF, ISNULL and COALESCE

Schema Binding Option in View

In SQL Server, the SCHEMABINDING option is used when creating a view to bind the view to the schema of the underlying tables or views. This option ensures that the underlying schema of the referenced objects remains unchanged, providing additional integrity and preventing accidental modifications that could break the view's dependencies.

When a view is created with the SCHEMABINDING option, it creates a dependency between the view and the referenced objects, such as tables or other views. If any referenced object's schema is modified, the view becomes invalid and requires recompilation.

Here's an example of creating a view with the SCHEMABINDING option:


CREATE VIEW SchemaBoundView
WITH SCHEMABINDING
AS
SELECT Column1, Column2, ...
FROM TableName
WHERE Condition;

In this example, the "SchemaBoundView" is created with the SCHEMABINDING option. The view references the table "TableName" and binds its schema to the view. This means that if the schema of the "TableName" changes, such as altering column names or data types, the view becomes invalid and requires recompilation to reflect the updated schema.

The SCHEMABINDING option offers several benefits, including:

  1. Dependency Control: By binding the view to the schema of the underlying objects, it ensures that any changes to the referenced objects' schema are intentional and do not break the view's dependencies.
  2. Query Optimization: The SCHEMABINDING option allows the query optimizer to generate more efficient query plans as it has knowledge of the view's dependencies and can optimize the execution accordingly.

To alter or drop objects that are referenced by a schema-bound view, you need to first remove the SCHEMABINDING option from the view or drop the view itself.

It's important to note that the SCHEMABINDING option is not suitable for all scenarios, especially when you require flexibility in modifying the underlying objects' schema. Therefore, you should carefully consider the impact and requirements before using the SCHEMABINDING option for your views.