1. Lexical and grammatical check of query statement 2. Submit the statement to the query optimizer of DBMS 3. The optimizer performs algebraic optimization and access path optimization 4. The query plan is generated by the precompiling module 5. Then submit it to the system for processing and execution at an appropriate time. 6. Finally, the execution result is returned to the user. Secondly, look at the data storage structure of SQL SERVER: the size of one page is 8K(8060) bytes, and eight pages are a panel, which is stored according to B-tree. 12, the difference between commit and rollback: rollback everything. Submit: Submit the current affairs. You don't need to write in dynamic SQL. If you want to write something, please write it outside, such as begin tran exec(@s) commit trans or write dynamic SQL as a function or stored procedure. 13. In the query Select statement, the number of rows returned is limited by the Where clause to avoid table scanning. If unnecessary data is returned, I/O resources of the server will be wasted, network burden will be increased and performance will be reduced. If the table is very large, it will be locked in the process of table scanning, and other connections are prohibited from accessing the table, which will have serious consequences. 14, SQL comment statement has no effect on execution 15, try not to use cursor, it takes up a lot of resources. If you need to execute line by line, try to use non-cursor technology, such as looping on the client, using temporary tables, table variables, using subqueries, using Case statements and so on. Cursors can be classified according to the extraction options supported by cursors: only forward must extract rows from the first row to the last row. FETCH NEXT is the only allowed fetch operation and the default mode. Scrollability can randomly select any line at any position of the cursor. Cursor technology has become very powerful under SQL2000, and its purpose is to support loops.
There are four concurrency options READ_ONLY: update by cursor positioning is not allowed, and there are no locks in the rows that make up the result set. Optimal value: optimistic concurrency control is a standard part of transaction control theory. Open concurrency control is used when the second user has little chance to update the row between opening the cursor and updating the row. When using this option to open a cursor, there is no lock to control the rows in it, which will help to maximize its processing power. If the user tries to modify a row, the current value of the row will be compared with the value obtained when the row was last extracted. If any value changes, the server will know that someone else has updated the row and will return an error. If the values are the same, the server will perform the modification. Select this concurrency option? Best row versioning: This optimistic concurrency control option is based on row versioning. For row versioning, the table must have a version identifier that the server can use to determine whether the row has changed since the cursor was read. In SQL Server, this performance is provided by the timestamp data type, which is a binary number indicating the relative order of changes in the database. Each database has a global current timestamp value: @@DBTS. Whenever a row with a timestamp column changes in any way, SQL Server first stores the current @@DBTS value in the timestamp column, and then increases the value of @@DBTS. If a table has a timestamp column, the timestamp is recorded at the row level. The server can compare the current timestamp value of the row with the timestamp value stored during the last extraction to determine whether the row has been updated. The server does not have to compare the values of all columns, only the timestamp columns. If the application requires open concurrency based on row versioning for tables without timestamp columns, the cursor defaults to value-based open concurrency control. Scroll LockThis option enables pessimistic concurrency control. In pessimistic concurrency control, when a database row is read into the cursor result set, the application will try to lock the database row. When a server cursor is used, an update lock is placed on the row when it is read into the cursor. If the cursor is opened in a transaction, the transaction update lock will remain until the transaction is committed or rolled back. When you select the next line, the cursor lock will be removed. If the cursor is opened outside the transaction, the lock will be discarded when the next row is fetched. Therefore, whenever users need completely pessimistic concurrency control, they should open cursors within transactions. Updating the lock will prevent any other task from acquiring the update lock or exclusive locks, thus preventing other tasks from updating the row. However, updating the lock does not prevent * * * from enjoying the lock, so it will not prevent other tasks from reading the row unless the second task also requests to use the update lock for reading. Rolling LockAccording to the lock hints specified in the SELECT statement of cursor definition, these cursor concurrency options can generate rolling locks. When extracting, the scroll lock will be acquired on each line, and it will remain until the next extraction or cursor closing, whichever occurs first. In the next extraction, the server acquires the scroll lock of the newly extracted row and releases the scroll lock of the last extracted row. Rolling locks are independent of transaction locks and can be maintained after commit or rollback operations. If the option to close the cursor at COMMIT time is off, the commit statement will not close any open cursors, and the scroll lock will be retained after commit to keep the extracted data isolated. The type of scroll lock obtained depends on the cursor concurrency option and the lock hint in the cursor SELECT statement. Lock prompt read-only optimistic numerical optimistic line version control lock silent unlock unlock unlock update NOLOCK unlock unlock hold lock * * * Enjoy * * Enjoy update UPDLOCK error update TABLOCKX error unlock unlock update other unlock unlock unlock unlock unlock update * Specifying NOLOCK prompt will make the table with specified prompt read-only in the cursor.
16, use Profiler to track the query, get the time needed for the query, and find out the problems of SQL; Optimize the index 17 with the index optimizer, and pay attention to the difference between UNion and UNion all. The combination is good 18. Pay attention to using DISTINCT, and don't use it when it is unnecessary. It will slow down the query like UNION. There are no duplicate records in the query. 19. Don't return unnecessary rows and columns when querying. Please use sp _ configure' query governor cost limit' or SET QUERY_GOVERNOR_COST_LIMIT to limit the resources consumed by the query. When the resource consumed by the evaluation query exceeds the limit, the server automatically cancels the query and kills it before the query. Set the lock time To set the lock time to 2 1, use select top 100/ 10% to limit the number of rows returned by the user, or set ROWCOUNT to limit the number of rows operated. 22. Before SQL2000, the following words were generally not used: "is null"