SlideShare une entreprise Scribd logo
1  sur  3
Télécharger pour lire hors ligne
Speed Up SQL Server Apps -- Visual Studio Magazine


                                                                                                  More Redmond Developer Network Sites                      >>>     RedDevNews.com         |   ADTmag.com          |     Events




         Redmond Report             Redmond IT                Redmond Partner                             Redmond Developer                     Visual Studio                 MCPmag.com               Virtualization Review




                                                                                                                                                                                     Enter Search Term or FindIT Code

                                                                                                                                                                                                                        Search
                                                                                                                                                                                                             Advanced Search


            HOME      SUBSCRIBE/RENEW        ADVERTISE         FREE NEWSLETTERS                          ABOUT US                TECH LIBRARY      EVENTS         RSS FEEDS




    Hot Topics                                             like
                                                           http://visualstudiomagazine.com/articles/2004/07/01/speed-up-sql-server-apps.aspx
                                                           AVo3oxuK
                                                                                                                                                                                               Most Popular Articles
    Visual Studio 2010                    Tweet      0          Like            5 people like this. Add a comment4
                                                                                people like this. Sign Up to see what
    NEW! Visual Studio                                                                                                                                                                            4 Must-Know
    2012/Win 8 5
    NEW! HTML                                                                                                                                                                                     Visual Studio
                                   Database Design                                                                                                                                                Keyboard
    ALM
    Agile/Scrum                    Speed Up SQL Server Apps                                                                                                                                       Shortcuts
                                                                                                                                                                                                  Animating
    SQL Server and SDS             Learn 10 useful tips and tricks that help boost SQL Server application performance.                                                                            Windows Phone
    Web Services                                                                                                                                                                                  Listbox Items
    .NET Framework                 By Roman Rehak          07/01/2004                                                                                                                             Free eBooks for
    SharePoint                                                                                                                                                                                    Data Developers
                                   Technology Toolbox: SQL Server 2000, ADO, ADO.NET
    XML/XAML                                                                                                                                                                                      Improved
                                   Developers love database programming tips, tricks, and workarounds—especially those that slash development time or                                             Combinations with
    C#
                                   boost application performance. Here's a collection of such nuggets for developing SQL Server applications.                                                     the BigInteger
    VB.NET                                                                                                                                                                                        Data Type
                                   1) Replace COUNT(*) With EXISTS When Checking for Existence
    Resources                                                                                                                                                                                     Develop Faster
                                   Developers often use the value from the COUNT(*) function when enforcing business rules in Transact-SQL code.
    2010 Buyers Guide                                                                                                                                                                             with Customized
                                   However, try the EXIST clause instead if you're using the COUNT(*) value only to evaluate whether you have at least one
                                                                                                                                                                                                  Visual Studio
    News                           row that meets certain conditions. For example, consider this code from the Northwind database:                                                                Templates
    Blogs
    In-Depth
    Code
    Columns
    Product Reviews
    Tech Library
    Sponsored Webcasts
    Subscribe/Renew
    Visual Studio Live!
    About Us
    Sitemap
    RSS Feeds




                                   IF (SELECT COUNT(*) FROM Orders
                                      WHERE ShipVia = 3) > 0
                                   PRINT 'You cannot delete this shipper'

                                   The execution plan shows that SQL Server has to read all 255 rows in the Orders table before evaluating the IF
                                   expression. You can achieve the same result more efficiently with EXISTS because the IF condition evaluates to true as
                                   soon as SQL Server finds the first occurrence of 3 in the ShipVia column:
                                   IF EXISTS (SELECT * FROM Orders
                                      WHERE ShipVia = 3)
                                   PRINT 'You cannot delete this shipper'

                                   The difference in total execution time isn't much in a sample database such as Northwind, but use this efficient query
                                   against an Orders table with millions of rows and you'll see a major speed improvement.

                                   2) Be Careful When Using WHERE IN and WHERE NOT IN
                                   SQL Server doesn't always choose an optimal execution plan when you have a substantial list of values in the WHERE IN
                                   clause. Using WHERE IN and WHERE NOT IN clauses in T-SQL code can produce an execution plan involving one or
                                   more nested loops. This increases the number of comparisons SQL Server must perform exponentially. Use the WHERE
                                   IN clause only if you have a short list of values you need to evaluate:
                                   USE Northwind
                                      --This query takes 9 ms to execute
                                   SELECT *
                                      FROM Customers




http://visualstudiomagazine.com/articles/2004/07/01/speed-up-sql-server-apps.aspx[08/29/2012 4:29:12 PM]
Speed Up SQL Server Apps -- Visual Studio Magazine

                                       WHERE CustomerID NOT IN
                                       (SELECT CustomerID FROM Orders)                                                                                           FREE WHITEPAPERS
                                   Replace the WHERE IN clause with OUTER JOIN if you're using a subquery to generate a potentially large list. Doing so          Five Tips for Delivering
                                   can improve performance significantly:                                                                                         Working Software with
                                                                                                                                                                  Agile
                                   USE Northwind
                                       --This query takes 3 ms to execute                                                                                         5 Ways Today’s Backup
                                   SELECT c.*                                                                                                                     and Restore
                                      FROM Customers c                                                                                                            Technologies Can Put
                                      LEFT OUTER JOIN Orders o
                                      ON o.CustomerID = c.CustomerID                                                                                              Your Business on the
                                      WHERE o.CustomerID IS NULL                                                                                                  Fast Track
                                   In this case, the second query uses LEFT OUTER JOIN, producing an execution plan that lets it run about three times            Microsoft Uses
                                                                                                                                                                  LiteSpeed® for SQL
                                   faster than the first query.
                                                                                                                                                                  Server from Quest
                                   The LEFT OUTER JOIN selects all rows from the Customer table—whether or not a customer placed any orders—and                   Software to Eliminate
                                                                                                                                                                  the Need for Additional
                                   joins them with the Orders table. Then the WHERE clause filters out the rows where the columns from the Orders table
                                                                                                                                                                  Storage
                                   have NULL values. Either way, you get a list of customers who placed no orders, but the second way gives SQL Server a
                                                                                                                                                                  Top 6 LiteSpeed
                                   lot less work to do. I rewrote a query recently using this technique, and the execution time went from 50 seconds to about     Features DBAs Should
                                   500 ms.                                                                                                                        Know About

                                   3) Randomize Resultset Orders With NewID()                                                                                            > MORE TECHLIBRARY

                                   You occasionally might need to randomize the order of the resultset retrieved from SQL Server. This is often the case in
                                   database searches where certain products or services would gain unfair advantage against others based simply on their
                                   name. I've seen a few clever (and not so clever) solutions for randomizing resultsets, but the solution is actually simple.
                                   You can use the NewID() function in Transact-SQL to generate a GUID for each row, then order the results by the
                                   generated GUID:
                                   SELECT * FROM Products
                                      ORDER BY NEWID()

                                   SQL Server returns products in a different order every time you run the query. You also can use this technique to return a
                                   random row from a table:
                                   SELECT TOP 1 * FROM Products
                                      ORDER BY NEWID()

                                   However, be careful when using this technique with large tables. You're only asking for one random row, but the execution
                                   plan shows that SQL Server gives you that random row only after reading each row in the table, generating a GUID for
                                   each row, then sorting all the rows. Consequently, SQL Server needs several seconds to give you a random row from a
                                   table with a few million rows. So don't use the "SELECT TOP 1?" technique on huge tables. Instead, restrict the random
                                   selection to a subset of the large table. Select a random range, then use "SELECT TOP 1?" within that range.

                                   4) Increase Default Packet Size for Large Data Fields
                                   SQL Server client applications communicate with instances of SQL Server through Net-Libraries. Client Net-Libraries and
                                   Server Net-Libraries communicate over the network by exchanging network packets. The size of network packets depends
                                   on the data access API you're using. The default packet size is 4,096 bytes in ADO and 8,192 bytes in ADO.NET.

                                   These sizes work well in most scenarios, but sometimes you can improve data exchange velocity greatly by increasing
                                   packet size—especially if you're sending or receiving large amounts of XML data, or if you're storing images in SQL Server.
                                   The client and server libraries must exchange and process fewer packets when you increase packet size. Maximum packet
                                   size is 32,767 bytes. You can increase packet size in ADO or ADO.NET simply by including the Packet Size property in the
                                   connection string:
                                   "?;Packet Size=32767;?"

                                   The speed gained in data upload and download depends on the size of your data fields and on your network topology. One
                                   of my applications stores XML data in SQL Server, with each XML field about 500K in size. My benchmarks show that the
                                   application exchanged XML data with SQL Server about twice as fast after increasing the packet size to 32,767 bytes.


                                                                                      1    2    3    NEXT »



                                                                          PRINTABLE FORMAT             E-MAIL THIS PAGE




                                    READER COMMENTS:




http://visualstudiomagazine.com/articles/2004/07/01/speed-up-sql-server-apps.aspx[08/29/2012 4:29:12 PM]
Speed Up SQL Server Apps -- Visual Studio Magazine


                                              Add Your Comments Now:
                                              Your Name: (optional)



                                              Your Email: (optional)



                                              Your Location: (optional)



                                              Comment:




                                              Please type the letters/numbers you see above




                                                                          Submit




                                                                                        Sponsored Links:

                                       Need to Clean Addresses or other Contact Data?
                                       Get the developer tools that make it easy; download a free trial.

                                       Have greater confidence in your barcode recognition
                                       Integrate 1D and 2D barcode recognition with Barcode Xpress v8

                                       dtSearch® Instantly Search Terabytes� for multiple file & data types
                                       25+ search options; 64-bit APIs; full eval; "lightening fast"-Red. Mag.




http://visualstudiomagazine.com/articles/2004/07/01/speed-up-sql-server-apps.aspx[08/29/2012 4:29:12 PM]

Contenu connexe

Tendances

Law & Order: Content Governance Strategies by Chrisitan Buckley - SPTechCon
Law & Order: Content Governance Strategies by Chrisitan Buckley - SPTechConLaw & Order: Content Governance Strategies by Chrisitan Buckley - SPTechCon
Law & Order: Content Governance Strategies by Chrisitan Buckley - SPTechCon
SPTechCon
 
Migrating to share point 2013 – practices and solution
Migrating to share point 2013 – practices and solutionMigrating to share point 2013 – practices and solution
Migrating to share point 2013 – practices and solution
Gopinath Dhandapani
 
Understanding the Tools and Features of Office 365 - New Zealand Digital Work...
Understanding the Tools and Features of Office 365 - New Zealand Digital Work...Understanding the Tools and Features of Office 365 - New Zealand Digital Work...
Understanding the Tools and Features of Office 365 - New Zealand Digital Work...
Michael Noel
 
Share point2010 sbtug_28april2010
Share point2010 sbtug_28april2010Share point2010 sbtug_28april2010
Share point2010 sbtug_28april2010
guest18ae5b00
 
The Future of your Desktop - Trends in Enterprise Mash-Up, Collaboration and ...
The Future of your Desktop - Trends in Enterprise Mash-Up, Collaboration and ...The Future of your Desktop - Trends in Enterprise Mash-Up, Collaboration and ...
The Future of your Desktop - Trends in Enterprise Mash-Up, Collaboration and ...
Matthias Zeller
 
SharePoint Server 2013 Farm Architecture and Performance by Ben Curry - SPTec...
SharePoint Server 2013 Farm Architecture and Performance by Ben Curry - SPTec...SharePoint Server 2013 Farm Architecture and Performance by Ben Curry - SPTec...
SharePoint Server 2013 Farm Architecture and Performance by Ben Curry - SPTec...
SPTechCon
 

Tendances (18)

Tutorial: Business-Critical SharePoint by Ben Curry - SPTechCon
Tutorial: Business-Critical SharePoint by Ben Curry - SPTechConTutorial: Business-Critical SharePoint by Ben Curry - SPTechCon
Tutorial: Business-Critical SharePoint by Ben Curry - SPTechCon
 
Office 2013: Upcoming Licensing, Pricing & Feature Changes
Office 2013: Upcoming Licensing, Pricing & Feature ChangesOffice 2013: Upcoming Licensing, Pricing & Feature Changes
Office 2013: Upcoming Licensing, Pricing & Feature Changes
 
Law & Order: Content Governance Strategies by Chrisitan Buckley - SPTechCon
Law & Order: Content Governance Strategies by Chrisitan Buckley - SPTechConLaw & Order: Content Governance Strategies by Chrisitan Buckley - SPTechCon
Law & Order: Content Governance Strategies by Chrisitan Buckley - SPTechCon
 
Share Point Saturday Bos Feb27 Hout Bw
Share Point Saturday Bos Feb27 Hout BwShare Point Saturday Bos Feb27 Hout Bw
Share Point Saturday Bos Feb27 Hout Bw
 
3 022
3 0223 022
3 022
 
Special Purpose Role-Based Clients for PLM using Aras
Special Purpose Role-Based Clients for PLM using ArasSpecial Purpose Role-Based Clients for PLM using Aras
Special Purpose Role-Based Clients for PLM using Aras
 
Part II: SharePoint 2013 Administration by Todd Klindt and Shane Young - SPTe...
Part II: SharePoint 2013 Administration by Todd Klindt and Shane Young - SPTe...Part II: SharePoint 2013 Administration by Todd Klindt and Shane Young - SPTe...
Part II: SharePoint 2013 Administration by Todd Klindt and Shane Young - SPTe...
 
Migrating to share point 2013 – practices and solution
Migrating to share point 2013 – practices and solutionMigrating to share point 2013 – practices and solution
Migrating to share point 2013 – practices and solution
 
Office 365; A Detailed Analysis - SPS Kampala 2017
Office 365; A Detailed Analysis - SPS Kampala 2017Office 365; A Detailed Analysis - SPS Kampala 2017
Office 365; A Detailed Analysis - SPS Kampala 2017
 
Understanding the Tools and Features of Office 365 - New Zealand Digital Work...
Understanding the Tools and Features of Office 365 - New Zealand Digital Work...Understanding the Tools and Features of Office 365 - New Zealand Digital Work...
Understanding the Tools and Features of Office 365 - New Zealand Digital Work...
 
Share point2010 sbtug_28april2010
Share point2010 sbtug_28april2010Share point2010 sbtug_28april2010
Share point2010 sbtug_28april2010
 
The Future of your Desktop - Trends in Enterprise Mash-Up, Collaboration and ...
The Future of your Desktop - Trends in Enterprise Mash-Up, Collaboration and ...The Future of your Desktop - Trends in Enterprise Mash-Up, Collaboration and ...
The Future of your Desktop - Trends in Enterprise Mash-Up, Collaboration and ...
 
10 Best SharePoint Features You’ve Never Used (But Should)
10 Best SharePoint Features You’ve Never Used (But Should)10 Best SharePoint Features You’ve Never Used (But Should)
10 Best SharePoint Features You’ve Never Used (But Should)
 
10 Ways SharePoint 2010 Will Impact your Notes Migration
10 Ways SharePoint 2010 Will Impact your Notes Migration10 Ways SharePoint 2010 Will Impact your Notes Migration
10 Ways SharePoint 2010 Will Impact your Notes Migration
 
SharePoint Server 2013 Farm Architecture and Performance by Ben Curry - SPTec...
SharePoint Server 2013 Farm Architecture and Performance by Ben Curry - SPTec...SharePoint Server 2013 Farm Architecture and Performance by Ben Curry - SPTec...
SharePoint Server 2013 Farm Architecture and Performance by Ben Curry - SPTec...
 
SQLUG event: An evening in the cloud: the old, the new and the big
 SQLUG event: An evening in the cloud: the old, the new and the big  SQLUG event: An evening in the cloud: the old, the new and the big
SQLUG event: An evening in the cloud: the old, the new and the big
 
Development of skype for business and knowledge of
Development of skype for business and knowledge ofDevelopment of skype for business and knowledge of
Development of skype for business and knowledge of
 
SharePoint 2010 Tools in Visual Studio 2010
SharePoint 2010 Tools in Visual Studio 2010SharePoint 2010 Tools in Visual Studio 2010
SharePoint 2010 Tools in Visual Studio 2010
 

Similaire à Speed up sql server apps - visual studio magazine

Integrating SharePoint 2010 and Visual Studio Lightswitch
Integrating SharePoint 2010 and Visual Studio LightswitchIntegrating SharePoint 2010 and Visual Studio Lightswitch
Integrating SharePoint 2010 and Visual Studio Lightswitch
Rob Windsor
 
SharePoint 2010 Business Intelligence
SharePoint 2010 Business IntelligenceSharePoint 2010 Business Intelligence
SharePoint 2010 Business Intelligence
Quang Nguyễn Bá
 
Employee Info Starter Kit
Employee Info Starter KitEmployee Info Starter Kit
Employee Info Starter Kit
joycsc
 
Sameer Bhandari Resume
Sameer Bhandari ResumeSameer Bhandari Resume
Sameer Bhandari Resume
sameerbhandari
 
Nitin_Krishna_Resume
Nitin_Krishna_ResumeNitin_Krishna_Resume
Nitin_Krishna_Resume
Nitin Krishna
 
Enabling End User And Ad Hoc Reporting With M S S Q L Server 2005 R...
Enabling  End  User And  Ad  Hoc  Reporting  With  M S  S Q L  Server 2005  R...Enabling  End  User And  Ad  Hoc  Reporting  With  M S  S Q L  Server 2005  R...
Enabling End User And Ad Hoc Reporting With M S S Q L Server 2005 R...
Joseph Lopez
 

Similaire à Speed up sql server apps - visual studio magazine (20)

Integrating SharePoint 2010 and Visual Studio Lightswitch
Integrating SharePoint 2010 and Visual Studio LightswitchIntegrating SharePoint 2010 and Visual Studio Lightswitch
Integrating SharePoint 2010 and Visual Studio Lightswitch
 
SharePoint 2010 Business Intelligence
SharePoint 2010 Business IntelligenceSharePoint 2010 Business Intelligence
SharePoint 2010 Business Intelligence
 
Molnar DEV307 OBA
Molnar DEV307 OBAMolnar DEV307 OBA
Molnar DEV307 OBA
 
Build business applications with visual studio light switch
Build business applications with visual studio light switchBuild business applications with visual studio light switch
Build business applications with visual studio light switch
 
Leveraging PowerPivot
Leveraging PowerPivotLeveraging PowerPivot
Leveraging PowerPivot
 
Office apps in Office 365 - Napa the next big thing
Office apps in Office 365 - Napa the next big thingOffice apps in Office 365 - Napa the next big thing
Office apps in Office 365 - Napa the next big thing
 
Employee Info Starter Kit
Employee Info Starter KitEmployee Info Starter Kit
Employee Info Starter Kit
 
Eclipse Developement @ Progress Software
Eclipse Developement @ Progress SoftwareEclipse Developement @ Progress Software
Eclipse Developement @ Progress Software
 
Best Practices for Upgrading Your Portal to SAP NetWeaver 7.3
Best Practices for Upgrading Your Portal to SAP NetWeaver 7.3Best Practices for Upgrading Your Portal to SAP NetWeaver 7.3
Best Practices for Upgrading Your Portal to SAP NetWeaver 7.3
 
Sameer Bhandari Resume
Sameer Bhandari ResumeSameer Bhandari Resume
Sameer Bhandari Resume
 
2019 -04-23 Austin, TX Tableau Users Group - Deployment: The Final Mile
2019 -04-23 Austin, TX Tableau Users Group - Deployment: The Final Mile2019 -04-23 Austin, TX Tableau Users Group - Deployment: The Final Mile
2019 -04-23 Austin, TX Tableau Users Group - Deployment: The Final Mile
 
SharePoint 2010 as a Development Platform
SharePoint 2010 as a Development PlatformSharePoint 2010 as a Development Platform
SharePoint 2010 as a Development Platform
 
Share point 2013 cop v4
Share point 2013 cop v4Share point 2013 cop v4
Share point 2013 cop v4
 
SharePoint 2013 Sneak Peek
SharePoint 2013 Sneak PeekSharePoint 2013 Sneak Peek
SharePoint 2013 Sneak Peek
 
Nitin_Krishna_Resume
Nitin_Krishna_ResumeNitin_Krishna_Resume
Nitin_Krishna_Resume
 
Sap bi roadmap overview 2010 sap inside track stl
Sap bi roadmap overview 2010 sap inside track stlSap bi roadmap overview 2010 sap inside track stl
Sap bi roadmap overview 2010 sap inside track stl
 
Public v1 real world example of azure functions serverless conf london 2016
Public v1 real world example of azure functions serverless conf london 2016 Public v1 real world example of azure functions serverless conf london 2016
Public v1 real world example of azure functions serverless conf london 2016
 
Soa204 Kawasaki Final
Soa204 Kawasaki FinalSoa204 Kawasaki Final
Soa204 Kawasaki Final
 
Business Intelligence For It Professionals Part 4 Scorecards Dashboards And...
Business Intelligence For It Professionals Part 4   Scorecards Dashboards And...Business Intelligence For It Professionals Part 4   Scorecards Dashboards And...
Business Intelligence For It Professionals Part 4 Scorecards Dashboards And...
 
Enabling End User And Ad Hoc Reporting With M S S Q L Server 2005 R...
Enabling  End  User And  Ad  Hoc  Reporting  With  M S  S Q L  Server 2005  R...Enabling  End  User And  Ad  Hoc  Reporting  With  M S  S Q L  Server 2005  R...
Enabling End User And Ad Hoc Reporting With M S S Q L Server 2005 R...
 

Plus de Kaing Menglieng

What is your sql server backup strategy tech_republic
What is your sql server backup strategy    tech_republicWhat is your sql server backup strategy    tech_republic
What is your sql server backup strategy tech_republic
Kaing Menglieng
 
Using sql server 2008's merge statement tech republic
Using sql server 2008's merge statement   tech republicUsing sql server 2008's merge statement   tech republic
Using sql server 2008's merge statement tech republic
Kaing Menglieng
 
Using object dependencies in sql server 2008 tech republic
Using object dependencies in sql server 2008   tech republicUsing object dependencies in sql server 2008   tech republic
Using object dependencies in sql server 2008 tech republic
Kaing Menglieng
 
Using hash fields in sql server tech republic
Using hash fields in sql server   tech republicUsing hash fields in sql server   tech republic
Using hash fields in sql server tech republic
Kaing Menglieng
 
Using grouping sets in sql server 2008 tech republic
Using grouping sets in sql server 2008   tech republicUsing grouping sets in sql server 2008   tech republic
Using grouping sets in sql server 2008 tech republic
Kaing Menglieng
 
Understand when to use user defined functions in sql server tech-republic
Understand when to use user defined functions in sql server   tech-republicUnderstand when to use user defined functions in sql server   tech-republic
Understand when to use user defined functions in sql server tech-republic
Kaing Menglieng
 
Sql server indexed views speed up your select queries part 1 - code-projec
Sql server indexed views   speed up your select queries  part 1 - code-projecSql server indexed views   speed up your select queries  part 1 - code-projec
Sql server indexed views speed up your select queries part 1 - code-projec
Kaing Menglieng
 
Sql server – query optimization – remove bookmark lookup – remove rid lookup
Sql server – query optimization – remove bookmark lookup – remove rid lookupSql server – query optimization – remove bookmark lookup – remove rid lookup
Sql server – query optimization – remove bookmark lookup – remove rid lookup
Kaing Menglieng
 
Sql server common interview questions and answers
Sql server   common interview questions and answersSql server   common interview questions and answers
Sql server common interview questions and answers
Kaing Menglieng
 
Sql server common interview questions and answers page 6
Sql server   common interview questions and answers page 6Sql server   common interview questions and answers page 6
Sql server common interview questions and answers page 6
Kaing Menglieng
 
Sql server common interview questions and answers page 5
Sql server   common interview questions and answers page 5Sql server   common interview questions and answers page 5
Sql server common interview questions and answers page 5
Kaing Menglieng
 
Sql server common interview questions and answers page 4
Sql server   common interview questions and answers page 4Sql server   common interview questions and answers page 4
Sql server common interview questions and answers page 4
Kaing Menglieng
 
Sql server common interview questions and answers page 2
Sql server   common interview questions and answers page 2Sql server   common interview questions and answers page 2
Sql server common interview questions and answers page 2
Kaing Menglieng
 
Sql server – 2008 – hardware and software requirements for installing sql se
Sql server – 2008 – hardware and software requirements for installing sql seSql server – 2008 – hardware and software requirements for installing sql se
Sql server – 2008 – hardware and software requirements for installing sql se
Kaing Menglieng
 
Speeding up queries with semi joins and anti-joins
Speeding up queries with semi joins and anti-joinsSpeeding up queries with semi joins and anti-joins
Speeding up queries with semi joins and anti-joins
Kaing Menglieng
 
See sql server graphical execution plans in action tech republic
See sql server graphical execution plans in action   tech republicSee sql server graphical execution plans in action   tech republic
See sql server graphical execution plans in action tech republic
Kaing Menglieng
 
Reviewing sql server permissions tech republic
Reviewing sql server permissions   tech republicReviewing sql server permissions   tech republic
Reviewing sql server permissions tech republic
Kaing Menglieng
 
Query optimization how to search millions of record in sql table faster -
Query optimization   how to search millions of record in sql table faster  -Query optimization   how to search millions of record in sql table faster  -
Query optimization how to search millions of record in sql table faster -
Kaing Menglieng
 
Optimize sql server queries with these advanced tuning techniques tech repu
Optimize sql server queries with these advanced tuning techniques   tech repuOptimize sql server queries with these advanced tuning techniques   tech repu
Optimize sql server queries with these advanced tuning techniques tech repu
Kaing Menglieng
 

Plus de Kaing Menglieng (20)

What is your sql server backup strategy tech_republic
What is your sql server backup strategy    tech_republicWhat is your sql server backup strategy    tech_republic
What is your sql server backup strategy tech_republic
 
Using sql server 2008's merge statement tech republic
Using sql server 2008's merge statement   tech republicUsing sql server 2008's merge statement   tech republic
Using sql server 2008's merge statement tech republic
 
Using object dependencies in sql server 2008 tech republic
Using object dependencies in sql server 2008   tech republicUsing object dependencies in sql server 2008   tech republic
Using object dependencies in sql server 2008 tech republic
 
Using hash fields in sql server tech republic
Using hash fields in sql server   tech republicUsing hash fields in sql server   tech republic
Using hash fields in sql server tech republic
 
Using grouping sets in sql server 2008 tech republic
Using grouping sets in sql server 2008   tech republicUsing grouping sets in sql server 2008   tech republic
Using grouping sets in sql server 2008 tech republic
 
Understand when to use user defined functions in sql server tech-republic
Understand when to use user defined functions in sql server   tech-republicUnderstand when to use user defined functions in sql server   tech-republic
Understand when to use user defined functions in sql server tech-republic
 
Sql server indexed views speed up your select queries part 1 - code-projec
Sql server indexed views   speed up your select queries  part 1 - code-projecSql server indexed views   speed up your select queries  part 1 - code-projec
Sql server indexed views speed up your select queries part 1 - code-projec
 
Sql server – query optimization – remove bookmark lookup – remove rid lookup
Sql server – query optimization – remove bookmark lookup – remove rid lookupSql server – query optimization – remove bookmark lookup – remove rid lookup
Sql server – query optimization – remove bookmark lookup – remove rid lookup
 
Sql server common interview questions and answers
Sql server   common interview questions and answersSql server   common interview questions and answers
Sql server common interview questions and answers
 
Sql server common interview questions and answers page 6
Sql server   common interview questions and answers page 6Sql server   common interview questions and answers page 6
Sql server common interview questions and answers page 6
 
Sql server common interview questions and answers page 5
Sql server   common interview questions and answers page 5Sql server   common interview questions and answers page 5
Sql server common interview questions and answers page 5
 
Sql server common interview questions and answers page 4
Sql server   common interview questions and answers page 4Sql server   common interview questions and answers page 4
Sql server common interview questions and answers page 4
 
Sql server common interview questions and answers page 2
Sql server   common interview questions and answers page 2Sql server   common interview questions and answers page 2
Sql server common interview questions and answers page 2
 
Sql server – 2008 – hardware and software requirements for installing sql se
Sql server – 2008 – hardware and software requirements for installing sql seSql server – 2008 – hardware and software requirements for installing sql se
Sql server – 2008 – hardware and software requirements for installing sql se
 
Speeding up queries with semi joins and anti-joins
Speeding up queries with semi joins and anti-joinsSpeeding up queries with semi joins and anti-joins
Speeding up queries with semi joins and anti-joins
 
Speed up sql
Speed up sqlSpeed up sql
Speed up sql
 
See sql server graphical execution plans in action tech republic
See sql server graphical execution plans in action   tech republicSee sql server graphical execution plans in action   tech republic
See sql server graphical execution plans in action tech republic
 
Reviewing sql server permissions tech republic
Reviewing sql server permissions   tech republicReviewing sql server permissions   tech republic
Reviewing sql server permissions tech republic
 
Query optimization how to search millions of record in sql table faster -
Query optimization   how to search millions of record in sql table faster  -Query optimization   how to search millions of record in sql table faster  -
Query optimization how to search millions of record in sql table faster -
 
Optimize sql server queries with these advanced tuning techniques tech repu
Optimize sql server queries with these advanced tuning techniques   tech repuOptimize sql server queries with these advanced tuning techniques   tech repu
Optimize sql server queries with these advanced tuning techniques tech repu
 

Speed up sql server apps - visual studio magazine

  • 1. Speed Up SQL Server Apps -- Visual Studio Magazine More Redmond Developer Network Sites >>> RedDevNews.com | ADTmag.com | Events Redmond Report Redmond IT Redmond Partner Redmond Developer Visual Studio MCPmag.com Virtualization Review Enter Search Term or FindIT Code Search Advanced Search HOME SUBSCRIBE/RENEW ADVERTISE FREE NEWSLETTERS ABOUT US TECH LIBRARY EVENTS RSS FEEDS Hot Topics like http://visualstudiomagazine.com/articles/2004/07/01/speed-up-sql-server-apps.aspx AVo3oxuK Most Popular Articles Visual Studio 2010 Tweet 0 Like 5 people like this. Add a comment4 people like this. Sign Up to see what NEW! Visual Studio 4 Must-Know 2012/Win 8 5 NEW! HTML Visual Studio Database Design Keyboard ALM Agile/Scrum Speed Up SQL Server Apps Shortcuts Animating SQL Server and SDS Learn 10 useful tips and tricks that help boost SQL Server application performance. Windows Phone Web Services Listbox Items .NET Framework By Roman Rehak 07/01/2004 Free eBooks for SharePoint Data Developers Technology Toolbox: SQL Server 2000, ADO, ADO.NET XML/XAML Improved Developers love database programming tips, tricks, and workarounds—especially those that slash development time or Combinations with C# boost application performance. Here's a collection of such nuggets for developing SQL Server applications. the BigInteger VB.NET Data Type 1) Replace COUNT(*) With EXISTS When Checking for Existence Resources Develop Faster Developers often use the value from the COUNT(*) function when enforcing business rules in Transact-SQL code. 2010 Buyers Guide with Customized However, try the EXIST clause instead if you're using the COUNT(*) value only to evaluate whether you have at least one Visual Studio News row that meets certain conditions. For example, consider this code from the Northwind database: Templates Blogs In-Depth Code Columns Product Reviews Tech Library Sponsored Webcasts Subscribe/Renew Visual Studio Live! About Us Sitemap RSS Feeds IF (SELECT COUNT(*) FROM Orders WHERE ShipVia = 3) > 0 PRINT 'You cannot delete this shipper' The execution plan shows that SQL Server has to read all 255 rows in the Orders table before evaluating the IF expression. You can achieve the same result more efficiently with EXISTS because the IF condition evaluates to true as soon as SQL Server finds the first occurrence of 3 in the ShipVia column: IF EXISTS (SELECT * FROM Orders WHERE ShipVia = 3) PRINT 'You cannot delete this shipper' The difference in total execution time isn't much in a sample database such as Northwind, but use this efficient query against an Orders table with millions of rows and you'll see a major speed improvement. 2) Be Careful When Using WHERE IN and WHERE NOT IN SQL Server doesn't always choose an optimal execution plan when you have a substantial list of values in the WHERE IN clause. Using WHERE IN and WHERE NOT IN clauses in T-SQL code can produce an execution plan involving one or more nested loops. This increases the number of comparisons SQL Server must perform exponentially. Use the WHERE IN clause only if you have a short list of values you need to evaluate: USE Northwind --This query takes 9 ms to execute SELECT * FROM Customers http://visualstudiomagazine.com/articles/2004/07/01/speed-up-sql-server-apps.aspx[08/29/2012 4:29:12 PM]
  • 2. Speed Up SQL Server Apps -- Visual Studio Magazine WHERE CustomerID NOT IN (SELECT CustomerID FROM Orders) FREE WHITEPAPERS Replace the WHERE IN clause with OUTER JOIN if you're using a subquery to generate a potentially large list. Doing so Five Tips for Delivering can improve performance significantly: Working Software with Agile USE Northwind --This query takes 3 ms to execute 5 Ways Today’s Backup SELECT c.* and Restore FROM Customers c Technologies Can Put LEFT OUTER JOIN Orders o ON o.CustomerID = c.CustomerID Your Business on the WHERE o.CustomerID IS NULL Fast Track In this case, the second query uses LEFT OUTER JOIN, producing an execution plan that lets it run about three times Microsoft Uses LiteSpeed® for SQL faster than the first query. Server from Quest The LEFT OUTER JOIN selects all rows from the Customer table—whether or not a customer placed any orders—and Software to Eliminate the Need for Additional joins them with the Orders table. Then the WHERE clause filters out the rows where the columns from the Orders table Storage have NULL values. Either way, you get a list of customers who placed no orders, but the second way gives SQL Server a Top 6 LiteSpeed lot less work to do. I rewrote a query recently using this technique, and the execution time went from 50 seconds to about Features DBAs Should 500 ms. Know About 3) Randomize Resultset Orders With NewID() > MORE TECHLIBRARY You occasionally might need to randomize the order of the resultset retrieved from SQL Server. This is often the case in database searches where certain products or services would gain unfair advantage against others based simply on their name. I've seen a few clever (and not so clever) solutions for randomizing resultsets, but the solution is actually simple. You can use the NewID() function in Transact-SQL to generate a GUID for each row, then order the results by the generated GUID: SELECT * FROM Products ORDER BY NEWID() SQL Server returns products in a different order every time you run the query. You also can use this technique to return a random row from a table: SELECT TOP 1 * FROM Products ORDER BY NEWID() However, be careful when using this technique with large tables. You're only asking for one random row, but the execution plan shows that SQL Server gives you that random row only after reading each row in the table, generating a GUID for each row, then sorting all the rows. Consequently, SQL Server needs several seconds to give you a random row from a table with a few million rows. So don't use the "SELECT TOP 1?" technique on huge tables. Instead, restrict the random selection to a subset of the large table. Select a random range, then use "SELECT TOP 1?" within that range. 4) Increase Default Packet Size for Large Data Fields SQL Server client applications communicate with instances of SQL Server through Net-Libraries. Client Net-Libraries and Server Net-Libraries communicate over the network by exchanging network packets. The size of network packets depends on the data access API you're using. The default packet size is 4,096 bytes in ADO and 8,192 bytes in ADO.NET. These sizes work well in most scenarios, but sometimes you can improve data exchange velocity greatly by increasing packet size—especially if you're sending or receiving large amounts of XML data, or if you're storing images in SQL Server. The client and server libraries must exchange and process fewer packets when you increase packet size. Maximum packet size is 32,767 bytes. You can increase packet size in ADO or ADO.NET simply by including the Packet Size property in the connection string: "?;Packet Size=32767;?" The speed gained in data upload and download depends on the size of your data fields and on your network topology. One of my applications stores XML data in SQL Server, with each XML field about 500K in size. My benchmarks show that the application exchanged XML data with SQL Server about twice as fast after increasing the packet size to 32,767 bytes. 1 2 3 NEXT » PRINTABLE FORMAT E-MAIL THIS PAGE READER COMMENTS: http://visualstudiomagazine.com/articles/2004/07/01/speed-up-sql-server-apps.aspx[08/29/2012 4:29:12 PM]
  • 3. Speed Up SQL Server Apps -- Visual Studio Magazine Add Your Comments Now: Your Name: (optional) Your Email: (optional) Your Location: (optional) Comment: Please type the letters/numbers you see above Submit Sponsored Links: Need to Clean Addresses or other Contact Data? Get the developer tools that make it easy; download a free trial. Have greater confidence in your barcode recognition Integrate 1D and 2D barcode recognition with Barcode Xpress v8 dtSearch® Instantly Search Terabytes� for multiple file & data types 25+ search options; 64-bit APIs; full eval; "lightening fast"-Red. Mag. http://visualstudiomagazine.com/articles/2004/07/01/speed-up-sql-server-apps.aspx[08/29/2012 4:29:12 PM]