We do have a few restrictions with the view’s definition in SQL Server. We cannot use each and every T-SQL statement inside a view’s definition. And, of course, this is one of the most commonly asked questions in technical interviews as well.
Here goes a list of restrictions with view’s definition:
- Every column, basically derived columns must have a column name.
- The INTO keyword cannot be used inside the SELECT statement.
- The COMPUTE BY clause cannot be used with the SELECT statement.
- Normally, the ORDER BY clause cannot be used with the SELECT statement. However, if we wish to use ORDER BY clause, we must use TOP(n) with the SELECT statement.
- A local or global temporary table (tables with # and ## sign) cannot be used inside a view.
- AFTER triggers cannot be associated with a view. However, we may associate INSTEAD OF trigger with a view.
- Rules and Defaults cannot be associated with a view.
- Full-Text index cannot be defined on a view.
- A view can have maximum of 1,024 column in its SELECT list.
- A view can have maximum of 32 levels of view nesting i.e. called nested views.
- All columns names must be explicitly specified when using WITH SCHEMABINDING option with a view’s definition. Even, when we are trying to pull all the columns out, we can’t use (*) sign. Instead, we need to write all column names explicitly.
This is all what I can compile that my memory could recall so far. If you have something to add/remove, which I missed out over here, please do put it in Leave a comment/Leave a Reply section below. I would appreciate your valuable contribution to the community.
No comments:
Post a Comment