Dynamic Sql Not so scary?

Slides:



Advertisements
Similar presentations
8 Copyright © 2004, Oracle. All rights reserved. Creating LOVs and Editors.
Advertisements

Oracle Developer Tools for Visual Studio.NET Curtis Rempe.
8 Copyright © 2004, Oracle. All rights reserved. Creating LOVs and Editors.
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 13 Managing Databases with SQL Server 2000.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-1 David M. Kroenke’s Chapter Seven: SQL for Database Construction and.
Database Design for DNN Developers Sebastian Leupold.
Dinamic SQL & Cursor. Why Dinamic SQL ? Sometimes there is a need to dynamically create a SQL statement on the fly and then run that command. This can.
Company LOGO 1 Database Creation and Maintenance Jorge G. Martinez.
Module 8: Implementing Stored Procedures. Introducing Stored Procedures Creating, Modifying, Dropping, and Executing Stored Procedures Using Parameters.
Module 9 Designing and Implementing Stored Procedures.
Programmatic SQL Shaista Khan CS 157B. Topic Embedded SQL statements in high-level programming languages.
SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database.
Access Database Things to Know…. Your database is managed from this DATABASE WINDOW:
Learningcomputer.com SQL Server 2008 –Views, Functions and Stored Procedures.
Dynamic SQL Writing Efficient Queries on the Fly ED POLLACK AUTOTASK CORPORATION DATABASE OPTIMIZATION ENGINEER.
In this session, you will learn to: Create and manage views Implement a full-text search Implement batches Objectives.
3 Copyright © 2006, Oracle. All rights reserved. Designing and Developing for Performance.
6 Copyright © 2009, Oracle. All rights reserved. Using Dynamic SQL.
DAY 20: ACCESS CHAPTERS 5, 6, 7 Larry Reaves October 28,
11 Copyright © 2009, Oracle. All rights reserved. Enhancing ETL Performance.
Introduction to SQL Server
Visual Basic 2010 How to Program
Parameter Sniffing in SQL Server Stored Procedures
Query Optimization Techniques
CS320 Web and Internet Programming SQL and MySQL
Dynamic SQL Writing Efficient Queries on the Fly
Making Your List and Checking It Twice
Creating Database Triggers
Chapter 6 - Database Implementation and Use
Creating LOVs and Editors
DBA and IT Professional for ~9 years. Currently I am a Data Architect
Troubleshooting SQL Server When You Cannot Access The Machine
Dynamic SQL: Writing Efficient Queries on the Fly
ITEC 313 Database Programming
Data Virtualization Demoette… Parameterized Queries
Using SQL Server through Command Prompt
LINQ to DATABASE-2.
Dynamic SQL Writing Efficient Queries on the Fly
Database Management  .
Relational Algebra Chapter 4, Part A
Marcos Freccia Stop everything! Top T-SQL tricks to a developer
Chapter 3 The Relational Model.
Query Optimization Techniques
MashZone Dynamic data sources
Exploring Microsoft® Access® 2016 Series Editor Mary Anne Poatsy
Declarative Creation of Enterprise Applications
Introduction to NetDB2 IST210.
Visual Studio Database Tools (aka SQL Server Data Tools)
Transactions, Locking and Query Optimisation
Advanced SQL: Views & Triggers
Dynamic SQL: Writing Efficient Queries on the Fly
Relational Algebra Chapter 4, Sections 4.1 – 4.2
Using JDeveloper.
DBA for ~4+years, IT Professional for 7.5 years.
Chapter 7 Using SQL in Applications
Database management concepts
Chapter 7 Using SQL in Applications
CS3220 Web and Internet Programming SQL and MySQL
Working With Databases
Chapter 11 Managing Databases with SQL Server 2000
SQL Server Fundamentals for Beginners
SQL Server Query Design and Optimization Recommendations
CS3220 Web and Internet Programming SQL and MySQL
Databases and Information Management
So What are Views and Triggers anyway?
Query Optimization Techniques
Dynamic SQL Konstantin Osipov, MySQL AB.
-Transactions in SQL -Constraints and Triggers
Chapter 3 The Relational Model
Navigating SSMS Primer for Beginners
Presentation transcript:

Dynamic Sql Not so scary? Trevor Makoni IQ Business

What we are not going to cover. Security risks from Sql injection. Differences between sp_executesql & exec. Query optimization. 2 | 4/15/2019 |

What we are not going to cover. Security risks from Sql injection. DECLARE @Sql VARCHAR(MAX), @EmployeeID = ‘1;drop table <table>’ SET @Sql = ' SELECT [Title] + '' '' + [FirstName] + '' '' + [LastName] as Name FROM [dbo].[Employees] WITH (NOLOCK) WHERE [EmployeeID] = ' + @EmployeeID; EXEC (@Sql); 3 | 4/15/2019 |

What we are going to cover. What is dynamic Sql? Where can we use dynamic Sql? Negative myths around dynamic Sql? How to effectively use dynamic Sql as a tool. Demo 4 | 4/15/2019 |

What is dynamic Sql? Dynamic SQL is a programming technique that enables you to build SQL statements dynamically at runtime. You can create more general purpose, flexible applications by using dynamic SQL because the full text of a SQL statement may be unknown at compilation. Dynamic SQL is simply a SQL statement that is composed on the fly before being executed. 4/15/2019 |

Where can we use dynamic Sql? You should use dynamic SQL in cases where static SQL does not support the operation you want to perform, or in cases where you do not know the exact SQL statements that must be executed by a SQL procedure. These SQL statements may depend on user input, or they may depend on processing work done by the program. 4/15/2019 |

Negative myths around dynamic Sql? Dynamic SQL is very difficult to understand let alone implement! Dynamic SQL takes too long to generate, using Static SQL is more time efficient! 4/15/2019 |

How to effectively use dynamic Sql as a tool. Steps to successful use of dynamic SQL. Understand what is needed. Identity any repeatable code. Have a clear strategy and solution first. Make sure you provide annotations in code. 4/15/2019 |

How to effectively use dynamic Sql as a tool. The best way to tackle this is to get straight onto the playing field. Let us look at a situation where a need arises that requires a user to copy a database without using the import wizard or database restore. Upfront we can see that static SQL will not cut it as there are a whole lot of unknowns in this task! 4/15/2019 |

Demo Let us walk through this process step by step… What objects need to be copied? The database Schemas Tables Primary Keys Foreign Keys Default Constraints Check Constraints Indexes 4/15/2019 |

Demo What objects need to be copied? Views Stored Procedures Functions Triggers Now that we know what is needed, let us step into some code…. Dynamic Sql demo 4/15/2019 |

12 | 4/15/2019 |