RSS

Some of Sql Server Circumstance


1.DECLARE @RowName Varchar(20)
SET @ROWName='SiteName'
SELECT * FROM M_Site ORDER BY @ROWName
What will be the Result?
ANSWER :
Msg 1008, Level 16, State 1, Line 3
The SELECT item identified by the ORDER BY number 1 contains a variable as part of the expression identifying a column position. Variables are only allowed when ordering by an expression referencing a column name.

2.SELECT 'test' Where exists(Select *)
Is the above Statement will throw error or Not, if Not what will be the Result?
ANSWER : test

3. What is Result for SELECT * , SELECT COUNT(*) and what is difference between them.

4. What is use of ‘WITH SCHEMABINDING’ in Sql Server?
Binds the view to the schema of the underlying table or tables. When SCHEMABINDING is specified, the base table or tables cannot be modified in a way that would affect the view definition. The view definition itself must first be modified or dropped to remove dependencies on the table that is to be modified. When you use SCHEMABINDING, the select statement must include the two-part names (schema. object) of tables, views, or user-defined functions that are referenced. All referenced objects must be in the same database.

Views or tables that participate in a view created with the SCHEMABINDING clause cannot be dropped unless that view is dropped or changed so that it no longer has schema binding. Otherwise, the Microsoft SQL Server 2005 Database Engine raises an error. Also, executing ALTER TABLE statements on tables that participate in views that have schema binding fail when these statements affect the view definition.
SCHEMABINDING cannot be specified if the view contains alias data type columns.

What does this mean?
Well, to put it simply, once you create a view with schema binding, you cannot change the underlying tables in a way that would break the view. Examples of this would be removing columns or dropping tables that are specified in the view.
WITH SCHEMABINDING can be used in Views and T-SQL Functions, but not in Stored Procedures.

0 comments:

Post a Comment