top of page

Dynamic SQL: What you need to know

  • Writer: sqldba
    sqldba
  • May 7, 2012
  • 1 min read

I use Dynamic SQL queries for everything.. yes even for buttering my bread and putting on my socks.

Yes, there are some security risks when using Dynamic SQL, but I know the risks and manage the implementation on code very carefully.

In most instances this relates to script I run to manage stuff or reports.

Where to begin:

1. Erland Sommarskog, dude you have made my life so much easier with this post. I keep it open in my browser at all times. The depth of information with regards to Dynamic SQL is really something special. Thanks Erland http://www.sommarskog.se/dynamic_sql.html
2. Pinal Dave, I cannot even begin to describe how much I have learned from Mr Pinal Dave on http://blog.sqlauthority.com. Thank you so much. http://blog.sqlauthority.com/tag/dynamic-sql/

There are a lot of things about Dynamic SQL that people do not know about when they start writing some fancy procedures and end up wrecking everything on the server.

Some of the considerations you need to think about as your coding skills improve in SQL and especially Dynamic SQL are:

  1. Set-Based Thinking

  2. Using table variables especially in DSQL

  3. Execution Plan Caching

  4. My posts that might be related

  5. Execution plan’s Plan A

  6. Indexes

  7. My posts that might be related.. but possibly not.. who knows these days

    1. Help! My server ate my SQL indexes


Recent Posts

See All
Where did my [sys].[sp_dboption] go?

Well in SQL Server 2012, to be quite blunt, [sys].[sp_dboption] has been deprecated, dumped, canned or if  you prefer, sent to Zim. Now isn’t that just dandy..because you will only realise this only w

 
 
 
SQL: what is this OPTION(OPTIMIZE FOR UNKNOWN)?

If you are into caching and reuse of existing query execution plans, which no doubt excites you as much as it does me, you probably use OPTION(OPTIMIZE FOR UNKNOWN) in most of your queries. If, howeve

 
 
 

Comments


Address

New Zealand - Auckland, Wellington, Christchurch
Australia - Brisbane, Perth
South Africa - Johannesburg, Cape Town
USA - Los Angeles

©2025 by SQLDBA.ORG Ltd

Contact

0800 000 174 (NZ)

+64 4 888 1683 (International)

  • LinkedIn
NZ_Service_Logo_NZ_Grown_RGB.png

Proudly 100% NZ owned and operated

bottom of page