![]() SQL Server Optimizing Update Queries for Large Data Volumes. Updating very large tables can be a time taking task and sometimes it might take hours to finish. In addition to this, it might also cause blocking issues. Here are few tips to SQL Server Optimizing the updates on large data volumes. 12 PL/SQL Optimization and Tuning. This chapter explains how the PL/SQL compiler optimizes your code and how to write efficient PL/SQL code and improve existing PL. This 5-day instructor led course provides students with the technical skills required to write basic Transact-SQL queries for Microsoft SQL Server 2014. A Cursor is a database object to retrieve data from a result set one row at a time, instead of the T-SQL commands that operate on all the rows in the result set at. ![]() Removing index on the column to be updated. Executing the update in smaller batches. Disabling Delete triggers. Replacing Update statement with a Bulk- Insert operation. With that being said, let’s apply the above points to optimize an update query. The code below creates a dummy table with 2. CREATE TABLE tblverylargetable. INT IDENTITY. col. CHAR(8. 00). col. CHAR(8. 00). col. CHAR(8. 00). DECLARE @i INT=0. WHILE( @i < 2. INSERT INTO tblverylargetable. VALUES ('Dummy'. Replicate('Dummy', 1. Replicate('Dummy', 1. SET @i=@i + 1. CREATE INDEX ix_col. ON tblverylargetable(col. CREATE INDEX ix_col. ON tblverylargetable(col. INCLUDE(col. 3)1. CREATETABLEtblverylargetable ( sno INTIDENTITY, col. CHAR(8. 00), col. CHAR(8. 00), col. CHAR(8. 00) )GODECLARE@i. INT=0. WHILE(@i< 2. BEGIN INSERTINTOtblverylargetable VALUES ('Dummy', Replicate('Dummy',1. Replicate('Dummy',1. SET@i=@i+1 ENDGOCREATEINDEXix_col. ONtblverylargetable(col. GOCREATEINDEXix_col. ONtblverylargetable(col. INCLUDE(col. 3)Consider the following update query which is to be optimized. It’s a very straight forward query to update a single column. UPDATE tblverylargetable. SET col. 1 = 'D'. WHERE col. 1 = 'Dummy'UPDATEtblverylargetable. SET col. 1='D'WHERE col. Dummy'The query takes 2: 1. Let’s look at the execution plan of the query shown below. In addition to the clustered index update, the index ix_col. The index update and Sort operation together take 6. Removing index on the column to be updated. The same query takes 1. Thus, an update query runs faster if the column to be updated is not an index key column. The index can always be created once the update completes. Executing the update in smaller batches The query can be further optimized by executing it in smaller batches. This is generally faster. The code below updates the records in batches of 2. DECLARE @i INT=1. WHILE( @i < = 1. UPDATE TOP(2. 00. SET col. 1 = 'D'. WHERE col. 1 = 'Dummy'. SET @i=@i + 1. ENDDECLARE@i. INT=1. WHILE(@i< =1. BEGIN UPDATETOP(2. SET col. 1='D' WHERE col. Dummy' SET@i=@i+1 ENDThe above query takes 6- 8 seconds to execute. When updating in batches, even if the update fails or it needs to be stopped, only rows from the current batch are rolled back. Disabling Delete triggers Triggers with cursors can extremely slow down the performance of a delete query. Disabling After delete triggers will considerably increase the query performance. Replacing Update statement with a Bulk- Insert operation An update statement is a fully logged operation and thus it will certainly take considerable amount of time if millions of rows are to be updated. The fastest way to speed up the update query is to replace it with a bulk- insert operation. It is a minimally logged operation in simple and Bulk- logged recovery model. This can be done easily by doing a bulk- insert in a new table and then rename the table to original one. The required indexes and constraint can be created on a new table as required. The code below shows how the update can be converted to a bulk- insert operation. It takes 4 seconds to execute. CASE col. 1. WHEN 'Dummy' THEN 'D'. ELSE col. 1. END AS col. INTO tblverylargetabletemp. FROM tblverylargetable. SELECTsno, CASEcol. WHEN'Dummy'THEN'D' ELSEcol. ENDAScol. 1, col. INTO tblverylargetabletemp. FROM tblverylargetable. The bulk- insert can then be further optimized to get additional performance boost. Hope this helps!!! Regards. Ahmad Osama. Like us on Face. Book | Follow us on Twitter | Join the fastest growing SQL Server group on Face. Book. Follow me on Twitter | Follow me on Face. Microsoft SQL Server - Wikipedia. Microsoft SQL Server. Developer(s)Microsoft. Initial release. April 2. SQL Server 1. 0. Stable release. SQL Server 2. 01. June 1, 2. 01. 6; 1. Development status. Active. Written in. C, C++Operating system. Linux, Microsoft Windows Server, Microsoft Windows. Available in. English, Chinese, French, German, Italian, Japanese, Korean, Portuguese (Brazil), Russian, Spanish and Indonesian[2]Type. Relational database management system. License. Proprietary software. Websitewww. microsoft. Microsoft SQL Server is a relational database management system developed by Microsoft. As a database server, it is a software product with the primary function of storing and retrieving data as requested by other software applications—which may run either on the same computer or on another computer across a network (including the Internet). Microsoft markets at least a dozen different editions of Microsoft SQL Server, aimed at different audiences and for workloads ranging from small single- machine applications to large Internet- facing applications with many concurrent users. History[edit]The history of Microsoft SQL Server begins with the first Microsoft SQL Server product – SQL Server 1. OS/2 operating system in 1. As of December 2. Microsoft: SQL Server 2. SQL Server 2. 00. R2. SQL Server 2. SQL Server 2. 01. SQL Server 2. 01. The current version is Microsoft SQL Server 2. June 1, 2. 01. 6. The RTM version is 1. SQL Server 2. 01. SQL Server 2. 01. Preview and is available for download on Microsoft's site. Editions[edit]Microsoft makes SQL Server available in multiple editions, with different feature sets and targeting different users. These editions are: [4][5]Mainstream editions[edit]Enterprise. SQL Server Enterprise Edition includes both the core database engine and add- on services, with a range of tools for creating and managing a SQL Server cluster. It can manage databases as large as 5. CPU cores).[6]Standard. SQL Server Standard edition includes the core database engine, along with the stand- alone services. It differs from Enterprise edition in that it supports fewer active instances (number of nodes in a cluster) and does not include some high- availability functions such as hot- add memory (allowing memory to be added while the server is still running), and parallel indexes. Web. SQL Server Web Edition is a low- TCO option for Web hosting. Business Intelligence. Introduced in SQL Server 2. Self Service and Corporate Business Intelligence. It includes the Standard Edition capabilities and Business Intelligence tools: Power. Pivot, Power View, the BI Semantic Model, Master Data Services, Data Quality Services and x. Velocity in- memory analytics.[7]Workgroup. SQL Server Workgroup Edition includes the core database functionality but does not include the additional services. Note that this edition has been retired in SQL Server 2. Express. SQL Server Express Edition is a scaled down, free edition of SQL Server, which includes the core database engine. While there are no limitations on the number of databases or users supported, it is limited to using one processor, 1 GB memory and 1. GB database files (4 GB database files prior to SQL Server Express 2. R2).[9] It is intended as a replacement for MSDE. Two additional editions provide a superset of features not in the original Express Edition. The first is SQL Server Express with Tools, which includes SQL Server Management Studio Basic. SQL Server Express with Advanced Services adds full- text search capability and reporting services.[1. Specialized editions[edit]Azure. Azure SQL Database is the cloud- based version of Microsoft SQL Server, presented as a platform as a service offering on Microsoft Azure. Compact (SQL CE)The compact edition is an embedded database engine. Unlike the other editions of SQL Server, the SQL CE engine is based on SQL Mobile (initially designed for use with hand- held devices) and does not share the same binaries. Due to its small size (1 MB DLL footprint), it has a markedly reduced feature set compared to the other editions. For example, it supports a subset of the standard data types, does not support stored procedures or Views or multiple- statement batches (among other limitations). It is limited to 4 GB maximum database size and cannot be run as a Windows service, Compact Edition must be hosted by the application using it. The 3. 5 version includes support for ADO. NET Synchronization Services. SQL CE does not support ODBC connectivity, unlike SQL Server proper. Developer. SQL Server Developer Edition includes the same features as SQL Server Enterprise Edition, but is limited by the license to be only used as a development and test system, and not as production server. Starting early 2. Microsoft made this version free of charge to the public.[1. Embedded (SSEE)SQL Server 2. Embedded Edition is a specially configured named instance of the SQL Server Express database engine which can be accessed only by certain Windows Services. Evaluation. SQL Server Evaluation Edition, also known as the Trial Edition, has all the features of the Enterprise Edition, but is limited to 1. Fast Track. SQL Server Fast Track is specifically for enterprise- scale data warehousing storage and business intelligence processing, and runs on reference- architecture hardware that is optimized for Fast Track.[1. Local. DBIntroduced in SQL Server Express 2. Local. DB is a minimal, on- demand, version of SQL Server that is designed for application developers.[1. It can also be used as an embedded database.[1. Analytics Platform System (APS)Formerly Parallel Data Warehouse (PDW) A massively parallel processing (MPP) SQL Server appliance optimized for large- scale data warehousing such as hundreds of terabytes.[1. Datawarehouse Appliance Edition. Pre- installed and configured as part of an appliance in partnership with Dell & HP base on the Fast Track architecture. This edition does not include SQL Server Integration Services, Analysis Services, or Reporting Services. Discontinued editions[edit]MSDEMicrosoft SQL Server Data Engine / Desktop Engine / Desktop Edition. SQL Server 7 and SQL Server 2. Intended for use as an application component, it did not include GUI management tools. Later, Microsoft also made available a web admin tool. Included with some versions of Microsoft Access, Microsoft development tools, and other editions of SQL Server.[1. Personal Edition. SQL Server 2. 00. Had workload or connection limits like MSDE, but no database size limit. Includes standard management tools. Intended for use as a mobile / disconnected proxy, licensed for use with SQL Server 2. Standard edition.[1. Datacenter. SQL Server 2. R2 Datacenter is a full- featured edition of SQL Server and is designed for datacenters that need high levels of application support and scalability. It supports 2. 56 logical processors and virtually unlimited memory and comes with Stream. Insight Premium edition.[1. The Datacenter edition has been retired in SQL Server 2. SQL Server 2. 01. Enterprise Edition.[8]Architecture[edit]The protocol layer implements the external interface to SQL Server. All operations that can be invoked on SQL Server are communicated to it via a Microsoft- defined format, called Tabular Data Stream (TDS). TDS is an application layer protocol, used to transfer data between a database server and a client. Initially designed and developed by Sybase Inc. Sybase SQL Server relational database engine in 1. Microsoft in Microsoft SQL Server, TDS packets can be encased in other physical transport dependent protocols, including TCP/IP, named pipes, and shared memory. Consequently, access to SQL Server is available over these protocols. In addition, the SQL Server API is also exposed over web services.[5]Data storage[edit]Data storage is a database, which is a collection of tables with typed columns. SQL Server supports different data types, including primary types such as Integer, Float, Decimal, Char (including character strings), Varchar (variable length character strings), binary (for unstructured blobs of data), Text (for textual data) among others. The rounding of floats to integers uses either Symmetric Arithmetic Rounding or Symmetric Round Down (fix) depending on arguments: SELECT Round(2. Microsoft SQL Server also allows user- defined composite types (UDTs) to be defined and used. It also makes server statistics available as virtual tables and views (called Dynamic Management Views or DMVs).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
October 2017
Categories |