![]() The first chapter after this introduction gives the basic commands to run dynamic SQL in a proper way and discusses traps you could encounter. However, you could argue that a client that only has fixed SQL strings is using static SQL, and one of the aims of the article is to demonstrate how client code should be written to achieve this. With a strict definition, static SQL can only occur in stored procedures and SQL scripts, since SQL in client code is always embedded into string literals in the client-side language. This can be done in client code or in a stored procedure. Some readers may ask: what is dynamic SQL? Dynamic SQL is when you write SQL code into a string variable and then execute the contents of that variable. (And at the same time as you use dynamic SQL all day long, you should attempt to prevent the devs from sticking dynamic SQL into the application code!) On the other hand, if you are a DBA, dynamic SQL is your best friend, because there are many DBA operations that can be automated with the help of dynamic SQL. Dynamic SQL certainly has its place in application code, but, as we shall see in this text, it also introduces complexity so there is all reason to hold back. If you are an application developer, you should be restrictive with your use of dynamic SQL. How much you should use dynamic SQL depends on your role. ![]() It is important to understand that dynamic SQL is an advanced feature, and preferably you should not start using dynamic SQL until you have mastered writing static queries. Quite often these posts are from inexperienced SQL users. I frequently see posts in SQL forums that use dynamic SQL or ask for it, when there is no need to, or the desire to use dynamic SQL is due to an earlier mistake in the design. Used in the right place, dynamic SQL is a tremendous asset, but dynamic SQL is also one of the most abused features in SQL Server. ![]() See here for font conventions used in this article. ![]() The Curse and Blessings of Dynamic SQL The Curse and Blessings of Dynamic SQLĪn SQL text by Erland Sommarskog, SQL Server MVP. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |