and ANSI_WARNINGS (which specifies ANSI SQL-92 standard behavior for several error conditions)session settings are off, instead of ending the query, the computation can have a NULL result.In practice, when either ARITHABORT or ANSI_WARNINGS settings is off, you cannot create anindex on a computed column or insert values into a table that has an index on a computed column becauseSQL Server detects such an attempt and returns an error. But SQL Server still requires you to guaranteethat the computation will not result in NULL values. The trick is to wrap the computed column's computationwith the ISNULL() function and supply an alternative value if the computation results in NULL:CREATE TABLE T2 (col1 int NOT NULL,col2 AS ISNULL(col1 + 1, 0) PRIMARY KEY)
Q. Why does my inline or embedded SQL run faster than my stored procedures?
A. Recompilations might be the source of the slower stored procedure speed. To find out for sure, you needto do some performance investigation, such as looking at Showplans for each type of query versus callingthe stored procedures and comparing query plan cache hits to cache misses. You can also try coding theobject owner for referenced tables, views, and procedures inside your stored procedures, as the followingexample shows:SELECT * FROM dbo.mytableThis technique helps you reuse plans and prevent cache misses.
Q. Why doesn't SQL Server permit an ORDER BY clause in the definition of a view?
A. SQL Server excludes an ORDER BY clause from a view to comply with the ANSI SQL-92 standard.Because analyzing the rationale for this standard requires a discussion of the underlying structure of thestructured query language (SQL) and the mathematics upon which it is based, we can't fully explain therestriction here. However, if you need to be able to specify an ORDER BY clause in a view, consider usingthe following workaround:USE pubsGOCREATE VIEW AuthorsByNameASSELECT TOP 100 PERCENT *FROM authorsORDER BY au_lname, au_fnameGOThe TOP construct, which Microsoft introduced in SQL Server 7.0, is most useful when you combine it withthe ORDER BY clause. The only time that SQL Server supports an ORDER BY clause in a view is when it isused in conjunction with the TOP keyword.Note that the TOP keyword is a SQL Server extension to the ANSI SQL-92 standard.
Q. Is using the TOP N clause faster than using SET ROWCOUNT N to return a specific number of rows from a query?
A. With proper indexes, the TOP N clause and SET ROWCOUNT N statement are equally fast, but withunsorted input from a heap, TOP N is faster. With unsorted input, the TOP N operator uses a small internalsorted temporary table in which it replaces only the last row. If the input is nearly sorted, the TOP N enginemust delete or insert the last row only a few times. Nearly sorted means you're dealing with a heap withordered inserts for the initial population and without many updates, deletes, forwarding pointers, and so onafterward. A nearly sorted heap is more efficient to sort than sorting a huge table. In a test that used TOP Nto sort a table with the same number of rows but with unordered inserts, TOP N was not as efficientanymore. Usually, the I/O time is the same both with an index and without; however, without an index SQL