T-Sql programming guidelines, in terms of:-
1. Commenting code
2. Code readability
3. General good practise
4. Defensive coding and error handling
5. Coding for performance and scalability
This document provides guidelines for developing databases and writing SQL code. It includes recommendations for naming conventions, variables, select statements, cursors, wildcard characters, joins, batches, stored procedures, views, data types, indexes and more. The guidelines suggest using more efficient techniques like derived tables, ANSI joins, avoiding cursors and wildcards at the beginning of strings. It also recommends measuring performance and optimizing for queries over updates.
This document discusses revisiting SQL basics and advanced topics. It covers objectives, assumptions, and topics to be covered including staying clean with conventions, data types, revisiting basics, joining, subqueries, joins versus subqueries, group by, set operations, and case statements. The topics sections provides details on each topic with examples to enhance SQL knowledge and write better queries.
This document provides an introduction to SQL (Structured Query Language). It defines SQL as a standard language for accessing and manipulating databases. The key points covered include:
- SQL lets you perform queries against a database to retrieve, insert, update, and delete data. It can also be used to create and modify database structures.
- Common SQL commands covered are SELECT, INSERT, UPDATE, DELETE, CREATE TABLE, ALTER TABLE, DROP TABLE.
- Additional SQL concepts explained are data types, WHERE clauses, ORDER BY clauses, GROUP BY clauses, and JOIN operations.
- RDBMS systems like MySQL, SQL Server, Oracle, etc. use SQL to communicate with the databases they manage.
SQL is a standard language used to manage data in relational database management systems. It can be used to create and modify database objects like tables and stored procedures, query and manipulate data, and set permissions. Common SQL statements include SELECT to query data, INSERT and UPDATE to modify data, CREATE and ALTER to define database structure, and DELETE to remove data. Transactions are managed using commands like COMMIT, ROLLBACK, and SAVEPOINT. Security is enforced using GRANT and REVOKE commands to manage user permissions on database objects.
The document discusses various SQL statements and functions used for managing databases and querying data. It provides the syntax for SQL statements like CREATE TABLE, INSERT, SELECT, UPDATE, DELETE and functions like COUNT, AVG, MIN, MAX, SUM to operate on data in database tables. It also covers statements for altering tables, joining tables, filtering rows with WHERE and HAVING clauses, removing duplicates with DISTINCT, and ordering results.
The document discusses various SQL concepts like database and tables, RDBMS terminology, SQL commands categories, data types, creating and manipulating tables. It explains concepts like primary key, foreign key, aggregate functions like MAX(), MIN(), AVG(), SUM(). Examples are provided for queries using SELECT, WHERE, ORDER BY, UPDATE and DELETE statements. Logical and relational operators used for filtering data in WHERE clause are also explained.
This document provides an introduction to SQL and database systems. It begins with example tables to demonstrate SQL concepts. It then covers the objectives of SQL, including allowing users to create database structures, manipulate data, and perform queries. Various SQL concepts are introduced such as data types, comparison operators, logical operators, and arithmetic operators. The document also discusses SQL statements for schema and catalog definitions, data definition, data manipulation, and other operators. Example SQL queries are provided to illustrate concepts around selecting columns, rows, sorting, aggregation, grouping, and more.
SQL is a standard language for accessing and manipulating databases. It allows users to perform functions like querying data, inserting records, updating records, and deleting records. The main SQL statements are SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, and DROP. SQL also includes clauses like WHERE, ORDER BY, GROUP BY and JOIN that allow users to filter and sort query results. Common data definition language statements are used to create and modify database structures like tables, indexes, and relationships.
This document provides guidelines for developing databases and writing SQL code. It includes recommendations for naming conventions, variables, select statements, cursors, wildcard characters, joins, batches, stored procedures, views, data types, indexes and more. The guidelines suggest using more efficient techniques like derived tables, ANSI joins, avoiding cursors and wildcards at the beginning of strings. It also recommends measuring performance and optimizing for queries over updates.
This document discusses revisiting SQL basics and advanced topics. It covers objectives, assumptions, and topics to be covered including staying clean with conventions, data types, revisiting basics, joining, subqueries, joins versus subqueries, group by, set operations, and case statements. The topics sections provides details on each topic with examples to enhance SQL knowledge and write better queries.
This document provides an introduction to SQL (Structured Query Language). It defines SQL as a standard language for accessing and manipulating databases. The key points covered include:
- SQL lets you perform queries against a database to retrieve, insert, update, and delete data. It can also be used to create and modify database structures.
- Common SQL commands covered are SELECT, INSERT, UPDATE, DELETE, CREATE TABLE, ALTER TABLE, DROP TABLE.
- Additional SQL concepts explained are data types, WHERE clauses, ORDER BY clauses, GROUP BY clauses, and JOIN operations.
- RDBMS systems like MySQL, SQL Server, Oracle, etc. use SQL to communicate with the databases they manage.
SQL is a standard language used to manage data in relational database management systems. It can be used to create and modify database objects like tables and stored procedures, query and manipulate data, and set permissions. Common SQL statements include SELECT to query data, INSERT and UPDATE to modify data, CREATE and ALTER to define database structure, and DELETE to remove data. Transactions are managed using commands like COMMIT, ROLLBACK, and SAVEPOINT. Security is enforced using GRANT and REVOKE commands to manage user permissions on database objects.
The document discusses various SQL statements and functions used for managing databases and querying data. It provides the syntax for SQL statements like CREATE TABLE, INSERT, SELECT, UPDATE, DELETE and functions like COUNT, AVG, MIN, MAX, SUM to operate on data in database tables. It also covers statements for altering tables, joining tables, filtering rows with WHERE and HAVING clauses, removing duplicates with DISTINCT, and ordering results.
The document discusses various SQL concepts like database and tables, RDBMS terminology, SQL commands categories, data types, creating and manipulating tables. It explains concepts like primary key, foreign key, aggregate functions like MAX(), MIN(), AVG(), SUM(). Examples are provided for queries using SELECT, WHERE, ORDER BY, UPDATE and DELETE statements. Logical and relational operators used for filtering data in WHERE clause are also explained.
This document provides an introduction to SQL and database systems. It begins with example tables to demonstrate SQL concepts. It then covers the objectives of SQL, including allowing users to create database structures, manipulate data, and perform queries. Various SQL concepts are introduced such as data types, comparison operators, logical operators, and arithmetic operators. The document also discusses SQL statements for schema and catalog definitions, data definition, data manipulation, and other operators. Example SQL queries are provided to illustrate concepts around selecting columns, rows, sorting, aggregation, grouping, and more.
SQL is a standard language for accessing and manipulating databases. It allows users to perform functions like querying data, inserting records, updating records, and deleting records. The main SQL statements are SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, and DROP. SQL also includes clauses like WHERE, ORDER BY, GROUP BY and JOIN that allow users to filter and sort query results. Common data definition language statements are used to create and modify database structures like tables, indexes, and relationships.
This document provides an overview of MySQL, a relational database management system that uses SQL. It discusses the different languages used in SQL - Data Definition Language (DDL) for creating and modifying database objects, Data Manipulation Language (DML) for inserting, updating, selecting and deleting data, Data Control Language (DCL) for granting and revoking user privileges, and Transaction Control Language (TCL) for managing transactions. Each section provides examples of key commands used for each language type and their purposes.
This document provides an overview of Chapter 3 from the textbook "Database System Concepts, 7th Ed." by Silberschatz, Korth and Sudarshan. It covers the history and components of SQL, data definition and manipulation languages, basic query structure, predicates, null values, and set operations in SQL. Key topics include the CREATE TABLE statement, data types, integrity constraints, SELECT statements, joins, ordering results, and aggregate functions.
Postgres expert, Bruce Momjian, as he discusses common table expressions (CTEs) and the ability to allow queries to be more imperative, allowing looping and processing hierarchical structures that are normally associated only with imperative languages.
Data Definition Language (DDL), Data Definition Language (DDL), Data Manipulation Language (DML) , Transaction Control Language (TCL) , Data Control Language (DCL) - , SQL Constraints
This document discusses various data types and SQL commands used in Oracle databases. It covers:
- Common data types like CHAR, VARCHAR2, NUMBER, DATE, LONG, RAW, BLOB, CLOB and how they store data.
- SQL commands for data definition (CREATE, ALTER, DROP), data manipulation (SELECT, INSERT, UPDATE, DELETE), and integrity constraints (PRIMARY KEY, FOREIGN KEY).
- Functions for calculations, string operations and data retrieval from tables.
Using SQL Queries to Insert, Update, Delete, and View Data.pptMohammedJifar1
This document provides an overview of Chapter 3 in the Guide to Oracle 10g, which covers using SQL queries to insert, update, delete, and view data. The key topics covered include running scripts to create database tables, inserting, updating, and deleting records, creating search conditions in queries, using sequences to generate keys, granting privileges on database objects, and writing queries to retrieve, calculate, group, and format data. The objectives are to learn how to perform these basic SQL operations for managing and querying data in an Oracle database.
SQLAlchemy is a Python SQL toolkit and object relational mapper that provides a full-featured SQL expression language while also allowing direct SQL execution. It features a core component that handles engine, connection, dialect, metadata, table, and column objects to work with databases, along with an ORM that builds on the core to allow mapping classes to tables with relationships and querying. SQLAlchemy supports all major databases including PostgreSQL, MySQL, MSSQL, SQLite, Sybase, Drizzle, Firebird, and Oracle.
SQL is a standard language for querying and manipulating data in relational databases. It contains five categories of statements: data definition language (DDL) for defining data structure, data manipulation language (DML) for managing data, data control language (DCL) for privileges, transaction control statements for transactions, and session control statements for sessions. Common DDL commands include CREATE, ALTER, and DROP for databases and tables. Common DML commands include SELECT, INSERT, UPDATE, and DELETE for querying and modifying data. Joins are used to combine data from two or more tables.
This document provides an overview of System i stored procedures. It discusses what stored procedures are, where they can be called from, why to use them over other options, how to create SQL and external stored procedures, and best practices. Examples are provided of RPG and SQL stored procedures that return recordsets. The document recommends practices like using stored procedures for data access and updates, limiting column selection for efficiency, and logging procedure execution for performance monitoring. Additional resources on the included CD are also listed.
Single-row functions can manipulate data items, accept arguments and return one value, and act on each row returned. There are various types of single-row functions including character, number, date, and conversion functions. Character functions manipulate character strings, number functions perform calculations, and date functions modify date formats. Functions allow data to be formatted, calculated, and converted as needed for different queries and outputs.
The document provides an introduction to the SQL language. It discusses the three main types of SQL statements: DDL, DML, and DCL. It also covers topics such as data types, constraints, functions, views, and how to create, modify and query tables. SQL is a language used to manage relational database management systems (RDBMS) and allows users to define, manipulate, and control access to data in a RDBMS.
SQL is a standard language for accessing and manipulating databases. It allows users to retrieve, insert, update, and delete data as well as create new databases and tables. Common SQL statements include SELECT, UPDATE, DELETE, and INSERT. SQL uses clauses, operators, and wildcards to filter records based on conditions. Some key points are that SQL is an ANSI standard but different versions exist, it allows querying and modifying data in databases, and is essential for interacting with relational database systems.
The document provides an overview of MySQL database concepts and basic CRUD operations. It discusses database, table, record, and field concepts. It also demonstrates how to navigate databases and tables in MySQL, and perform basic create, read, update, and delete operations through queries like CREATE, SELECT, UPDATE, DELETE, and DROP. These include creating databases and tables, inserting and retrieving data, updating fields, and deleting records or entire tables.
Bootstrap is the popular HTML, CSS and JavaScript framework for developing a responsive and mobile friendly website.
Bootstrap all topics of Bootstrap such as jumbotron, table, button, grid, form, image, alert, wells, container, carousel, panels, glyphicon, badges, labels, progress bar, pagination, pager, list group, dropdown, collapse,tabs, pills, navbar, inputs, modals, tooltip, popover and scrollspy.
The SELECT statement is used to retrieve data from one or more tables. It allows you to select specific columns, rows, and expressions. The general syntax includes keywords like SELECT, FROM, WHERE, and clauses for filtering, sorting, grouping, and joining results. Examples demonstrate how to select all data, particular rows and columns, use aliases, DISTINCT, comparison operators, patterns, ranges, and handle NULL values.
This document provides an overview of C# programming basics, including:
- C# is an object-oriented language where the basic unit is a class containing methods and variables.
- A C# program consists of at least one class that must contain a Main method, which acts as the program entry point.
- The document discusses basic C# concepts like variables, data types, operators, conditional statements, loops, methods, and arrays.
- It also covers how to compile and run a simple "Hello World" C# program, and provides examples of different programming constructs.
This document discusses code standards and best practices for writing maintainable code. It emphasizes the importance of code organization, documentation, naming conventions, indentation, brace styles, commenting, consistency, and readability. Specific guidelines are provided for naming conventions, indentation, brace styles, and commenting. The document stresses choosing and adhering to coding standards to promote uniformity and minimize issues when collaborating on projects.
This document provides an overview and introduction to Oracle SQL basics. It covers topics such as installing Oracle software like the database, Java SDK, and SQL Developer tool. It then discusses database concepts like what a database and table are. It also covers database fundamentals including SQL queries, functions, joins, constraints, views and other database objects. The document provides examples and explanations of SQL statements and database components.
This document provides an agenda for a T-SQL training session. It discusses selecting a database management system (SQL Server) and database (PUBS) to use. It introduces basic SQL concepts like databases, tables, connecting to a database. It demonstrates simple SELECT queries, concatenating columns, using aliases. It also covers filtering queries using WHERE clauses with comparison operators, compound criteria with AND/OR, ranges, wildcards, escape characters and pattern matching. Negation is also introduced using NOT and comparison operators.
This document provides an agenda for an introductory course on T-SQL. The course will cover topics such as null values, distinct, having vs where clauses, data types, creating and modifying tables, joins, subqueries, functions, errors, variables, control flow and stored procedures. It provides background that SQL was first introduced in 1970 and was developed by Donald Chamberlin and Raymond Boyce at IBM as SEQUEL, later changed to SQL. The next session will cover writing basic queries.
This document provides an overview of MySQL, a relational database management system that uses SQL. It discusses the different languages used in SQL - Data Definition Language (DDL) for creating and modifying database objects, Data Manipulation Language (DML) for inserting, updating, selecting and deleting data, Data Control Language (DCL) for granting and revoking user privileges, and Transaction Control Language (TCL) for managing transactions. Each section provides examples of key commands used for each language type and their purposes.
This document provides an overview of Chapter 3 from the textbook "Database System Concepts, 7th Ed." by Silberschatz, Korth and Sudarshan. It covers the history and components of SQL, data definition and manipulation languages, basic query structure, predicates, null values, and set operations in SQL. Key topics include the CREATE TABLE statement, data types, integrity constraints, SELECT statements, joins, ordering results, and aggregate functions.
Postgres expert, Bruce Momjian, as he discusses common table expressions (CTEs) and the ability to allow queries to be more imperative, allowing looping and processing hierarchical structures that are normally associated only with imperative languages.
Data Definition Language (DDL), Data Definition Language (DDL), Data Manipulation Language (DML) , Transaction Control Language (TCL) , Data Control Language (DCL) - , SQL Constraints
This document discusses various data types and SQL commands used in Oracle databases. It covers:
- Common data types like CHAR, VARCHAR2, NUMBER, DATE, LONG, RAW, BLOB, CLOB and how they store data.
- SQL commands for data definition (CREATE, ALTER, DROP), data manipulation (SELECT, INSERT, UPDATE, DELETE), and integrity constraints (PRIMARY KEY, FOREIGN KEY).
- Functions for calculations, string operations and data retrieval from tables.
Using SQL Queries to Insert, Update, Delete, and View Data.pptMohammedJifar1
This document provides an overview of Chapter 3 in the Guide to Oracle 10g, which covers using SQL queries to insert, update, delete, and view data. The key topics covered include running scripts to create database tables, inserting, updating, and deleting records, creating search conditions in queries, using sequences to generate keys, granting privileges on database objects, and writing queries to retrieve, calculate, group, and format data. The objectives are to learn how to perform these basic SQL operations for managing and querying data in an Oracle database.
SQLAlchemy is a Python SQL toolkit and object relational mapper that provides a full-featured SQL expression language while also allowing direct SQL execution. It features a core component that handles engine, connection, dialect, metadata, table, and column objects to work with databases, along with an ORM that builds on the core to allow mapping classes to tables with relationships and querying. SQLAlchemy supports all major databases including PostgreSQL, MySQL, MSSQL, SQLite, Sybase, Drizzle, Firebird, and Oracle.
SQL is a standard language for querying and manipulating data in relational databases. It contains five categories of statements: data definition language (DDL) for defining data structure, data manipulation language (DML) for managing data, data control language (DCL) for privileges, transaction control statements for transactions, and session control statements for sessions. Common DDL commands include CREATE, ALTER, and DROP for databases and tables. Common DML commands include SELECT, INSERT, UPDATE, and DELETE for querying and modifying data. Joins are used to combine data from two or more tables.
This document provides an overview of System i stored procedures. It discusses what stored procedures are, where they can be called from, why to use them over other options, how to create SQL and external stored procedures, and best practices. Examples are provided of RPG and SQL stored procedures that return recordsets. The document recommends practices like using stored procedures for data access and updates, limiting column selection for efficiency, and logging procedure execution for performance monitoring. Additional resources on the included CD are also listed.
Single-row functions can manipulate data items, accept arguments and return one value, and act on each row returned. There are various types of single-row functions including character, number, date, and conversion functions. Character functions manipulate character strings, number functions perform calculations, and date functions modify date formats. Functions allow data to be formatted, calculated, and converted as needed for different queries and outputs.
The document provides an introduction to the SQL language. It discusses the three main types of SQL statements: DDL, DML, and DCL. It also covers topics such as data types, constraints, functions, views, and how to create, modify and query tables. SQL is a language used to manage relational database management systems (RDBMS) and allows users to define, manipulate, and control access to data in a RDBMS.
SQL is a standard language for accessing and manipulating databases. It allows users to retrieve, insert, update, and delete data as well as create new databases and tables. Common SQL statements include SELECT, UPDATE, DELETE, and INSERT. SQL uses clauses, operators, and wildcards to filter records based on conditions. Some key points are that SQL is an ANSI standard but different versions exist, it allows querying and modifying data in databases, and is essential for interacting with relational database systems.
The document provides an overview of MySQL database concepts and basic CRUD operations. It discusses database, table, record, and field concepts. It also demonstrates how to navigate databases and tables in MySQL, and perform basic create, read, update, and delete operations through queries like CREATE, SELECT, UPDATE, DELETE, and DROP. These include creating databases and tables, inserting and retrieving data, updating fields, and deleting records or entire tables.
Bootstrap is the popular HTML, CSS and JavaScript framework for developing a responsive and mobile friendly website.
Bootstrap all topics of Bootstrap such as jumbotron, table, button, grid, form, image, alert, wells, container, carousel, panels, glyphicon, badges, labels, progress bar, pagination, pager, list group, dropdown, collapse,tabs, pills, navbar, inputs, modals, tooltip, popover and scrollspy.
The SELECT statement is used to retrieve data from one or more tables. It allows you to select specific columns, rows, and expressions. The general syntax includes keywords like SELECT, FROM, WHERE, and clauses for filtering, sorting, grouping, and joining results. Examples demonstrate how to select all data, particular rows and columns, use aliases, DISTINCT, comparison operators, patterns, ranges, and handle NULL values.
This document provides an overview of C# programming basics, including:
- C# is an object-oriented language where the basic unit is a class containing methods and variables.
- A C# program consists of at least one class that must contain a Main method, which acts as the program entry point.
- The document discusses basic C# concepts like variables, data types, operators, conditional statements, loops, methods, and arrays.
- It also covers how to compile and run a simple "Hello World" C# program, and provides examples of different programming constructs.
This document discusses code standards and best practices for writing maintainable code. It emphasizes the importance of code organization, documentation, naming conventions, indentation, brace styles, commenting, consistency, and readability. Specific guidelines are provided for naming conventions, indentation, brace styles, and commenting. The document stresses choosing and adhering to coding standards to promote uniformity and minimize issues when collaborating on projects.
This document provides an overview and introduction to Oracle SQL basics. It covers topics such as installing Oracle software like the database, Java SDK, and SQL Developer tool. It then discusses database concepts like what a database and table are. It also covers database fundamentals including SQL queries, functions, joins, constraints, views and other database objects. The document provides examples and explanations of SQL statements and database components.
This document provides an agenda for a T-SQL training session. It discusses selecting a database management system (SQL Server) and database (PUBS) to use. It introduces basic SQL concepts like databases, tables, connecting to a database. It demonstrates simple SELECT queries, concatenating columns, using aliases. It also covers filtering queries using WHERE clauses with comparison operators, compound criteria with AND/OR, ranges, wildcards, escape characters and pattern matching. Negation is also introduced using NOT and comparison operators.
This document provides an agenda for an introductory course on T-SQL. The course will cover topics such as null values, distinct, having vs where clauses, data types, creating and modifying tables, joins, subqueries, functions, errors, variables, control flow and stored procedures. It provides background that SQL was first introduced in 1970 and was developed by Donald Chamberlin and Raymond Boyce at IBM as SEQUEL, later changed to SQL. The next session will cover writing basic queries.
This document provides information about an upcoming SQL Saturday Night event on March 30, 2013 that will focus on using T-SQL. The presentation will be recorded so that those unable to attend can view it later. Attendees are asked to change their virtual cards to a specific color if they are unable to hear the presenter. The presentation will be free and begin in 1 minute.
This document provides an overview of SQL programming. It covers the history of SQL and SQL Server, SQL fundamentals including database design principles like normalization, and key SQL statements like SELECT, JOIN, UNION and stored procedures. It also discusses database objects, transactions, and SQL Server architecture concepts like connections. The document is intended as a training guide, walking through concepts and providing examples to explain SQL programming techniques.
This document provides a template for selecting targeted content standards to meet a specified goal statement. It includes sections for listing the standards IDs, descriptions, and rationales for how each standard aligns with the overall big idea or enduring understanding. A process is outlined to first identify applicable standards based on the goal, then evaluate them based on criteria like endurance and leverage to refine the list. It also includes a QA checklist to ensure the targeted standards meet certain criteria.
Standards And Documentation Authoritative Technology WebsitesLloyd_Wedes
This document provides instructions for using the delicious.com database to search for websites on specific subjects and keywords. It explains how to choose a main subject or keyword to view related websites, and then add additional keywords to narrow the search results. Clicking on individual keywords or websites will modify or reset the search. The document encourages using the database to research standards, documents, and potential association memberships.
Michael Haneke is an Austrian filmmaker known for his dark and disturbing films that often feature dysfunctional families and ambiguous narratives. He frequently shocks and confuses audiences. Haneke's films exhibit recurrent characteristics of style that serve as his signature, suggesting he is an auteur. For example, Funny Games uses a perfect family preyed upon by outsiders to critique audiences who consume on-screen violence. When remaking Funny Games, Haneke kept the same themes and meaning to target those audiences in the English-speaking world. A scene from the film casually depicts the killers discussing murder while getting food, parallel to how audiences view on-screen violence as entertainment.
1) The document is a script for a presentation on graphic design in presentations. It discusses starting with a blank canvas rather than a template, using analog techniques like sketching before digitizing, and curating an image bank from multiple sources.
2) The presenter emphasizes reflecting on teaching style and curating an organized image bank from many contributors to have high quality, sourced materials.
3) Questions are included throughout to engage attendees in evaluating design principles like visual superiority and simplification of information.
Avoiding cursors with sql server 2005 tech republicKaing Menglieng
The document discusses how to avoid using cursors in SQL Server 2005 when executing queries. It presents a scenario where cursors would traditionally be used to loop through inventory transaction records and calculate the remaining inventory each day. It then shows two methods using new SQL 2005 features like common table expressions and window functions to solve the problem with a single query instead of cursors. Avoiding cursors improves performance since sets are processed at once rather than row-by-row.
This document provides an overview and programming tips for using SQL procedural language (SQL PL) stored procedures on DB2 for z/OS. It discusses various features and enhancements for SQL PL including compound blocks, templates, dynamic SQL, XML support, array data types, global variables, and autonomous transactions. The document also provides examples and best practices for writing SQL procedures, including handling naming resolution, using templates for readability, and working with arrays and dynamic SQL.
Performance tuning involves improving the performance of computer systems, typically databases. It involves identifying high load or inefficient SQL statements, verifying execution plans, and implementing corrective actions. Tuning goals include reducing workload through better queries and plans, balancing workload between peak and off-peak times, and parallelizing workload. High load statements can be identified through SQL tracing tools, and TKProf can analyze trace files to identify top SQL and plans.
This presentation features the fundamentals of SQL tunning like SQL Processing, Optimizer and Execution Plan, Accessing Tables, Performance Improvement Consideration Partition Technique. Presented by Alphalogic Inc : https://www.alphalogicinc.com/
This document provides an overview of SQL procedural language (SQL PL) programming tips for DB2 stored procedures on z/OS. It discusses topics like when to use native SQL procedures, benefits of templates, compound blocks, dynamic SQL, XML support, and new features in DB2 11 like array data types and global variables. The document is intended for application developers to help simplify applications using SQL PL procedures.
The document discusses using Statspack and AWR (Automatic Workload Repository) to analyze SQL performance and identify poorly performing queries. It provides examples of Statspack reports and how to interpret them to find SQL statements that are doing full table scans, experiencing buffer cache misses, or are inefficient due to lack of bind variables. The document also discusses how to identify SQL statements that are causing excessive sorting.
The document summarizes upcoming improvements and enhancements in MySQL 5.5 related to scalability and performance. Key points include:
1) Semi-synchronous replication, the Performance Schema, SIGNAL/RESIGNAL, and additional partitioning options to improve data integrity and monitoring.
2) Major InnoDB improvements including a faster memory allocator, improved change buffering, prefetching and flushing techniques, and additional background threads to increase scalability.
3) Methods to control resource usage like I/O capacity, purge scheduling, and flushing for better performance under varying workloads.
The document discusses tuning SQL queries in Oracle databases. It begins by noting that while tools can help, there is no single process for tuning every query as each case depends on factors like the schema design, data distribution and how the optimizer chooses a plan. The document then provides a methodology for investigating and tuning a query with poor performance, including getting the execution plan, checking it visually, and identifying possible causes like stale statistics, missing indexes or inefficient SQL.
The document provides information about stored procedures in databases:
- A stored procedure is a way to encapsulate repetitive tasks like queries into reusable code blocks stored in the database.
- Stored procedures offer advantages like precompiled execution for improved performance, reduced network traffic, code reuse, and enhanced security.
- The example shows how to create a stored procedure using delimiters to change parsing behavior and pass parameters to a procedure. Cursors allow fetching multiple rows from a result set into variables.
Design and develop with performance in mind
Establish a tuning environment
Index wisely
Reduce parsing
Take advantage of Cost Based Optimizer
Avoid accidental table scans
Optimize necessary table scans
Optimize joins
Use array processing
Consider PL/SQL for “tricky” SQL
This document discusses stored procedures in MySQL and MSSQL, including their advantages, syntax, and examples. It also covers the differences between procedures and functions, and provides an example of creating a trigger to update total department salaries when employees are inserted, updated, or deleted.
The document discusses various techniques for optimizing database performance in Oracle, including:
- Using the cost-based optimizer (CBO) to choose the most efficient execution plan based on statistics and hints.
- Creating appropriate indexes on columns used in predicates and queries to reduce I/O and sorting.
- Applying constraints and coding practices like limiting returned rows to improve query performance.
- Tuning SQL statements through techniques like predicate selectivity, removing unnecessary objects, and leveraging indexes.
SQL Server 2008 Development for ProgrammersAdam Hutson
The document outlines a presentation by Adam Hutson on SQL Server 2008 development for programmers, including an overview of CRUD and JOIN basics, dynamic versus compiled statements, indexes and execution plans, performance issues, scaling databases, and Adam's personal toolbox of SQL scripts and templates. Adam has 11 years of database development experience and maintains a blog with resources for SQL topics.
SQL Server 2000 Research Series - Transact SQLJerry Yang
The document discusses key concepts in Transact-SQL including stored procedures, data types, variables, flow control statements, and functions. It covers topics such as stored procedure design, data type categories, local and global variables, conditional and looping statements, and built-in versus user-defined functions. The summary provides an overview of the document's content for technical integration and SQL training purposes.
The document provides various PHP and MySQL tips and best practices including:
1) Signing queries and using comments helps when debugging slow queries and process lists.
2) The "LOAD DATA INFILE" statement is 20 times faster than INSERT for loading data.
3) Normalizing data and avoiding storing multiple values in a single column improves performance.
4) Joins should be used instead of executing multiple queries to compare rows.
Loginworks Softwares is a USA & INDIA based provider of data mining services organisations. Our data mining services utilise advanced statistical and multivariate techniques to identify areas of opportunity within your organization’s data. Loginworks is a software and services provider, with particular expertise in processing, analyzing, visualizing and sharing market research data. The Data Mining Group has the capability and experience to identify value-adding trends and relationships within your data. These provide you with greater insight and empower you to improve your strategies, affordable costs and boost revenue.
https://www.loginworks.com/data-mining/
This document provides 9 hints for optimizing Oracle database performance:
1. Take a methodical and empirical approach to tuning by focusing on root causes, measuring performance before and after changes, and avoiding "silver bullets".
2. Design databases and applications with performance in mind from the beginning.
3. Index wisely by only creating useful indexes that improve performance without excessive overhead.
4. Leverage built-in Oracle tools like DBMS_XPLAN and SQL Trace to measure performance.
5. Tune the optimizer by adjusting parameters and statistics to encourage better execution plans.
6. Focus SQL and PL/SQL tuning on problem queries, joins, sorts, and DML statements.
7. Address
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...Alex Zaballa
Oracle Database 12c includes many new tuning features for developers and DBAs. Some key features include:
- Multitenant architecture allows multiple pluggable databases to consolidate workloads on a single database instance for improved utilization and administration.
- In-memory column store enables real-time analytics on frequently accessed data held entirely in memory for faster performance.
- New SQL syntax like FETCH FIRST for row limiting and offsetting provides more readable and intuitive replacements for previous techniques.
- Adaptive query optimization allows queries to utilize different execution plans like switching between nested loops and hash joins based on runtime statistics for improved performance.
This document provides an overview of how to deploy a SQL Server 2019 Big Data Cluster on Kubernetes. It discusses setting up infrastructure with Ubuntu templates, installing Kubespray to manage the Kubernetes cluster lifecycle, and using azdata to deploy the Big Data Cluster. Key steps include creating an Ansible inventory, configuring storage with labels and profiles, and deploying the cluster. The document also offers tips on sizing, upgrades, and next steps like load balancing and monitoring.
Data relay introduction to big data clustersChris Adkin
This document provides an overview of SQL Server 2019 Big Data Clusters, which enable hybrid SQL Server/Spark scale-out data platforms that run on Kubernetes. Big Data Clusters are available in public preview and will generally be available in the second half of 2019. They provide a true scale-out data platform for aggregating data from various sources, using data science tools with sensitive data on the same platform, and storing/querying large amounts of unstructured data with SQL Server tools.
Continuous Integration With Jenkins Docker SQL ServerChris Adkin
This document discusses using containers and Jenkins for continuous integration and deployment pipelines. It provides an overview of build pipelines, how they can be implemented as code in Jenkins using scripts or declarative syntax. Demonstrations are shown for simple webhooks, multi-branch pipelines, using build slaves in containers, image layering, and fully containerizing a build environment. Tips are provided on constructing Dockerfiles and using timeouts.
The traditional topics of memory pressure, page life expectancy and memory grants have been covered to the point of saturation in the SQL community, in this deck I want to cover some topics relating to memory and SQL Server which might be considered "Off-piste" but are as equally relevant if not more so in terms of getting the best possible performance out of SQL Server.
Scaling sql server 2014 parallel insertChris Adkin
A slide deck on how to get the best possible performance out of the parallel insert feature introduced in SQL Server 2014 as presented at SQL Bits XIV.
Sql server engine cpu cache as the new ramChris Adkin
This document discusses CPU cache and memory architectures. It begins with a diagram showing the cache hierarchy from L1 to L3 cache within a CPU. It then discusses how larger CPUs have multiple cores, each with their own L1 and L2 caches sharing a larger L3 cache. The document highlights how main memory bandwidth has not kept up with increasing CPU speeds and caches.
An introduction to column store indexes and batch modeChris Adkin
This document discusses column store databases and how they work. It explains that column store databases store data by column rather than row to better utilize modern CPU architectures. It describes how column stores use compression techniques like run-length encoding and dictionaries. It also demonstrates how batch processing and sorting data can improve performance of queries against column stores by keeping more data in CPU caches.
Column store indexes and batch processing mode (nx power lite)Chris Adkin
This document discusses SQL Server performance tuning with a focus on leveraging CPU caches through column store compression. It explains how column store compression can bridge the performance gap between IO subsystems and modern processors by breaking data through levels of compression to pipeline batches into CPU caches. Examples are provided showing significant performance improvements from column store compression and clustering over row-based storage and no compression.
Building scalable application with sql serverChris Adkin
Chris Adkin has 15 years of IT experience and 14 years of experience as a DBA working with various sectors. He has over 10 years of experience with SQL Server from version 2000. He provides his email and Twitter contact information. The document then discusses various topics related to database design and performance including OLTP vs OLAP characteristics, data modeling best practices, indexing strategies, query optimization techniques, and concurrency control methods.
A presentation on best practices for J2EE scalability from requirements gathering through to implementation, including design and architecture along the way.
The document summarizes findings from a project testing batch processing performance using J2EE. It discusses considerations for batch frameworks, infrastructure, caching, logging, design challenges, and whether to use batch processing. It also outlines the design of the batch process used, including leveraging raw JDBC, Oracle caching, and tools for performance monitoring.
Fueling AI with Great Data with Airbyte WebinarZilliz
This talk will focus on how to collect data from a variety of sources, leveraging this data for RAG and other GenAI use cases, and finally charting your course to productionalization.
Ivanti’s Patch Tuesday breakdown goes beyond patching your applications and brings you the intelligence and guidance needed to prioritize where to focus your attention first. Catch early analysis on our Ivanti blog, then join industry expert Chris Goettl for the Patch Tuesday Webinar Event. There we’ll do a deep dive into each of the bulletins and give guidance on the risks associated with the newly-identified vulnerabilities.
Main news related to the CCS TSI 2023 (2023/1695)Jakub Marek
An English 🇬🇧 translation of a presentation to the speech I gave about the main changes brought by CCS TSI 2023 at the biggest Czech conference on Communications and signalling systems on Railways, which was held in Clarion Hotel Olomouc from 7th to 9th November 2023 (konferenceszt.cz). Attended by around 500 participants and 200 on-line followers.
The original Czech 🇨🇿 version of the presentation can be found here: https://www.slideshare.net/slideshow/hlavni-novinky-souvisejici-s-ccs-tsi-2023-2023-1695/269688092 .
The videorecording (in Czech) from the presentation is available here: https://youtu.be/WzjJWm4IyPk?si=SImb06tuXGb30BEH .
Skybuffer SAM4U tool for SAP license adoptionTatiana Kojar
Manage and optimize your license adoption and consumption with SAM4U, an SAP free customer software asset management tool.
SAM4U, an SAP complimentary software asset management tool for customers, delivers a detailed and well-structured overview of license inventory and usage with a user-friendly interface. We offer a hosted, cost-effective, and performance-optimized SAM4U setup in the Skybuffer Cloud environment. You retain ownership of the system and data, while we manage the ABAP 7.58 infrastructure, ensuring fixed Total Cost of Ownership (TCO) and exceptional services through the SAP Fiori interface.
Best 20 SEO Techniques To Improve Website Visibility In SERPPixlogix Infotech
Boost your website's visibility with proven SEO techniques! Our latest blog dives into essential strategies to enhance your online presence, increase traffic, and rank higher on search engines. From keyword optimization to quality content creation, learn how to make your site stand out in the crowded digital landscape. Discover actionable tips and expert insights to elevate your SEO game.
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Jeffrey Haguewood
Sidekick Solutions uses Bonterra Impact Management (fka Social Solutions Apricot) and automation solutions to integrate data for business workflows.
We believe integration and automation are essential to user experience and the promise of efficient work through technology. Automation is the critical ingredient to realizing that full vision. We develop integration products and services for Bonterra Case Management software to support the deployment of automations for a variety of use cases.
This video focuses on integration of Salesforce with Bonterra Impact Management.
Interested in deploying an integration with Salesforce for Bonterra Impact Management? Contact us at sales@sidekicksolutionsllc.com to discuss next steps.
HCL Notes and Domino License Cost Reduction in the World of DLAUpanagenda
Webinar Recording: https://www.panagenda.com/webinars/hcl-notes-and-domino-license-cost-reduction-in-the-world-of-dlau/
The introduction of DLAU and the CCB & CCX licensing model caused quite a stir in the HCL community. As a Notes and Domino customer, you may have faced challenges with unexpected user counts and license costs. You probably have questions on how this new licensing approach works and how to benefit from it. Most importantly, you likely have budget constraints and want to save money where possible. Don’t worry, we can help with all of this!
We’ll show you how to fix common misconfigurations that cause higher-than-expected user counts, and how to identify accounts which you can deactivate to save money. There are also frequent patterns that can cause unnecessary cost, like using a person document instead of a mail-in for shared mailboxes. We’ll provide examples and solutions for those as well. And naturally we’ll explain the new licensing model.
Join HCL Ambassador Marc Thomas in this webinar with a special guest appearance from Franz Walder. It will give you the tools and know-how to stay on top of what is going on with Domino licensing. You will be able lower your cost through an optimized configuration and keep it low going forward.
These topics will be covered
- Reducing license cost by finding and fixing misconfigurations and superfluous accounts
- How do CCB and CCX licenses really work?
- Understanding the DLAU tool and how to best utilize it
- Tips for common problem areas, like team mailboxes, functional/test users, etc
- Practical examples and best practices to implement right away
In the rapidly evolving landscape of technologies, XML continues to play a vital role in structuring, storing, and transporting data across diverse systems. The recent advancements in artificial intelligence (AI) present new methodologies for enhancing XML development workflows, introducing efficiency, automation, and intelligent capabilities. This presentation will outline the scope and perspective of utilizing AI in XML development. The potential benefits and the possible pitfalls will be highlighted, providing a balanced view of the subject.
We will explore the capabilities of AI in understanding XML markup languages and autonomously creating structured XML content. Additionally, we will examine the capacity of AI to enrich plain text with appropriate XML markup. Practical examples and methodological guidelines will be provided to elucidate how AI can be effectively prompted to interpret and generate accurate XML markup.
Further emphasis will be placed on the role of AI in developing XSLT, or schemas such as XSD and Schematron. We will address the techniques and strategies adopted to create prompts for generating code, explaining code, or refactoring the code, and the results achieved.
The discussion will extend to how AI can be used to transform XML content. In particular, the focus will be on the use of AI XPath extension functions in XSLT, Schematron, Schematron Quick Fixes, or for XML content refactoring.
The presentation aims to deliver a comprehensive overview of AI usage in XML development, providing attendees with the necessary knowledge to make informed decisions. Whether you’re at the early stages of adopting AI or considering integrating it in advanced XML development, this presentation will cover all levels of expertise.
By highlighting the potential advantages and challenges of integrating AI with XML development tools and languages, the presentation seeks to inspire thoughtful conversation around the future of XML development. We’ll not only delve into the technical aspects of AI-powered XML development but also discuss practical implications and possible future directions.
5th LF Energy Power Grid Model Meet-up SlidesDanBrown980551
5th Power Grid Model Meet-up
It is with great pleasure that we extend to you an invitation to the 5th Power Grid Model Meet-up, scheduled for 6th June 2024. This event will adopt a hybrid format, allowing participants to join us either through an online Mircosoft Teams session or in person at TU/e located at Den Dolech 2, Eindhoven, Netherlands. The meet-up will be hosted by Eindhoven University of Technology (TU/e), a research university specializing in engineering science & technology.
Power Grid Model
The global energy transition is placing new and unprecedented demands on Distribution System Operators (DSOs). Alongside upgrades to grid capacity, processes such as digitization, capacity optimization, and congestion management are becoming vital for delivering reliable services.
Power Grid Model is an open source project from Linux Foundation Energy and provides a calculation engine that is increasingly essential for DSOs. It offers a standards-based foundation enabling real-time power systems analysis, simulations of electrical power grids, and sophisticated what-if analysis. In addition, it enables in-depth studies and analysis of the electrical power grid’s behavior and performance. This comprehensive model incorporates essential factors such as power generation capacity, electrical losses, voltage levels, power flows, and system stability.
Power Grid Model is currently being applied in a wide variety of use cases, including grid planning, expansion, reliability, and congestion studies. It can also help in analyzing the impact of renewable energy integration, assessing the effects of disturbances or faults, and developing strategies for grid control and optimization.
What to expect
For the upcoming meetup we are organizing, we have an exciting lineup of activities planned:
-Insightful presentations covering two practical applications of the Power Grid Model.
-An update on the latest advancements in Power Grid -Model technology during the first and second quarters of 2024.
-An interactive brainstorming session to discuss and propose new feature requests.
-An opportunity to connect with fellow Power Grid Model enthusiasts and users.
OpenID AuthZEN Interop Read Out - AuthorizationDavid Brossard
During Identiverse 2024 and EIC 2024, members of the OpenID AuthZEN WG got together and demoed their authorization endpoints conforming to the AuthZEN API
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfMalak Abu Hammad
Discover how MongoDB Atlas and vector search technology can revolutionize your application's search capabilities. This comprehensive presentation covers:
* What is Vector Search?
* Importance and benefits of vector search
* Practical use cases across various industries
* Step-by-step implementation guide
* Live demos with code snippets
* Enhancing LLM capabilities with vector search
* Best practices and optimization strategies
Perfect for developers, AI enthusiasts, and tech leaders. Learn how to leverage MongoDB Atlas to deliver highly relevant, context-aware search results, transforming your data retrieval process. Stay ahead in tech innovation and maximize the potential of your applications.
#MongoDB #VectorSearch #AI #SemanticSearch #TechInnovation #DataScience #LLM #MachineLearning #SearchTechnology
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxSitimaJohn
Ocean Lotus cyber threat actors represent a sophisticated, persistent, and politically motivated group that poses a significant risk to organizations and individuals in the Southeast Asian region. Their continuous evolution and adaptability underscore the need for robust cybersecurity measures and international cooperation to identify and mitigate the threats posed by such advanced persistent threat groups.
3. Comments and exception handling have been
purposely omitted from code fragments in the interest
of brevity, such that each fragment can fit onto one
slide.
Disclaimer
4. Comments and exception handling have been
purposely omitted from code fragments in the interest
of brevity, such that each fragment can fit onto one
slide.
Disclaimer
6. All code should be self documenting.
T-SQL code artefacts, triggers, stored procedures and
functions should have a standard comment banner.
Comment code at all points of interest, describe why
and not what.
Avoid in line comments.
Comments
7. Comment banners should include:-
Author details.
A brief description of what the code does.
Narrative comments for all arguments.
Narrative comments for return types.
Change control information.
An example is provided on the next slide
Comment Banners
8. CREATE PROCEDURE
/*===================================================================================*
//*
/*
*/
*/Name :
uspMyProc
/*
/*
/*
/*
/*
/*
(
*/
*/
*/
*/
*/
*/
Description: Stored
should
procedure to demonstrate what a specimen comment banner
look like.
Parameters :
@Parameter1 int, /* First parameter passed into procedure. */
*/
*/
/* ---------------------------------------------------------------------------
@Parameter2 int /* Second parameter passed into procedure.
)
/*
/*
/*
/*
/*
/*
/*
/*
*/
*/
*/
*/
*/
*/
*/
*/
Change History
~~~~~~~~~~~~~~
Version
-------
1.0
Author
--------------------
C. J. Adkin
Date
--------
09/08/11
Ticket
------
3525
Description
------------------------------------
Initial version created.
/*===================================================================================*/
AS
BEGIN
.
.
Comment Banner Example
9. -- This is an example of an inline comment
Why are these bad ?
Because a careless backspace can turn a useful statement
into a commented out one.
But my code is always thoroughly tested
NO EXCSUSE, always code defensively
Use /* */ comments instead.
Use Of Inline Comments
10. Use and adhere to naming conventions.
Use meaningful object names.
Never prefix application stored procedures with sp
SQL Server will always scan through the system
catalogue first, before executing such procedures
Bad for performance
Naming Conventions
11. Use ANSI SQL join syntax over none ANSI syntax.
Be consistent when
Camel case
Pascal case
Use of upper case
Be consistent when
using case:-
for reserved key words
indenting and stacking text.
Code Readability
13. Never blindly take technical hints and tips written in a blog or
presentation as gospel.
Test your assumptions using “Scientific method”, i.e.:-
Use test cases which use consistent test data across all tests,
production realistic data is preferable.
If the data is commercially sensitive, e.g. bank account details, keep
the volume and distribution the same, obfuscate the sensitive
parts out.
Only change one thing at a time, so as to be able to gauge the
impact of the change accurately and know what effected the
change.
The “Scientific Method” Approach
14. • For performance related tests always clear the
procedure and buffer cache out, so that results
not skewed between tests, use the following:-
are
–
–
–
CHECKPOINT
DBCC FREEPROCCACHE
DBCC DROPCLEANBUFFERS
The “Scientific Method” Approach
15. A term coined by Jeff Moden, a MVP and frequent poster on
SQL Server Central.com .
Alludes to:-
Coding in procedural 3GL way instead of a set based way.
Chronic performance of row by row oriented processing.
Abbreviated to RBAR, pronounced Ree-bar.
Avoid “Row by agonising row”
Techniques
16. Code whereby result sets and table contents are
processed line by line, typically using cursors.
Correlated subqueries.
User Defined Functions.
Iterating through results sets as ADO objects in
Server Integration Services looping containers.
SQL
Where “Row by agonising row”
Takes Place
17. A simple, but contrived query written against the
AdventureWorkds2008R2 database.
The first query will use nested subqueries.
The second will use derived tables.
Sub-Query Example
19. SELECT ProductID,
Quantity
FROM (SELECT TOP 1
LocationID
AdventureWorks.Production.Location Loc
CostRate = (SELECT MAX(CostRate)
FROM
WHERE
FROM AdventureWorks.Production.Location) ) dt,
AdventureWorks.Production.ProductInventory Pi
Pi.LocationID = dt.LocationIDWHERE
Sub-Query Example Without RBAR
20.
What is the difference between the two queries ?.
Query 1, cost = 0.299164
Query 2, cost = 0.0202938
What is the crucial difference ?
Table spool operation in the first plan has been executed 1069 times.
This happens to be the number of rows in the ProductInventory table.
The RBAR Versus The Non-RBAR
Approach Quantified
21. Row oriented processing may be unavoidable under certain
circumstances:-
The processing of one row depends on the state of one or more
previous rows in a result set.
The row processing logic involves a change to the global state of the
database and therefore cannot be encapsulated in a function.
In this case there are ways to use cursors in a very efficient manner
As per the next three slides.
Efficient Techniques For RBAR When
It Cannot Be Avoided
22. Elapsed time 00:22:27.892
DECLARE @MaxRownum
@OrderId
@i
int,
int,
int;
SET @i = 1;
CREATE TABLE #OrderIds (
rownum
OrderId
int IDENTITY (1, 1),
int
);
INSERT
SELECT
FROM
INTO #OrderIds
SalesOrderID
Sales.SalesOrderDetail;
SELECT
FROM
@MaxRownum = MAX(rownum)
#OrderIds;
WHILE @i <
BEGIN
SELECT
FROM
WHERE
@MaxRownum
@OrderId = OrderId
#OrderIds
rownum = @i;
SET @i = @i + 1;
END;
RBAR Without A Cursor
23. Elapsed time 00:00:03.106
DECLARE @s int;
DECLARE c CURSOR FOR
SELECT
FROM
SalesOrderID
Sales.SalesOrderDetail;
OPEN c;
FETCH NEXT FROM c INTO @s;
WHILE @@FETCH_STATUS = 0
BEGIN
FETCH NEXT FROM c INTO @s;
END;
CLOSE c;
DEALLOCATE c;
RBAR With A Cursor
24. Elapsed time 00:00:01.555
DECLARE @s int;
DECLARE c CURSOR FAST_FORWARD FOR
SELECT
FROM
SalesOrderID
Sales.SalesOrderDetail;
OPEN c;
FETCH NEXT FROM c INTO @s;
WHILE @@FETCH_STATUS = 0
BEGIN
FETCH NEXT FROM c INTO @s;
END;
CLOSE c;
DEALLOCATE c;
RBAR With An Optimised Cursor
25. No T-SQL language feature is a “Panacea to all
For example:-
Avoid RBAR logic where possible
Avoid nesting cursors
But cursors do have their uses.
Be aware of the FAST_FORWARD optimisation, applicable
when:-
The data being retrieved is not being modified
The cursor is being scrolled through in a forward only
direction
ills”.
Cursor “RBAR” Morale Of The Story
26. When using SQL Server 2005 onwards:-
Use TRY CATCH blocks.
Make the event logged in CATCH block verbose enough to
allow the exceptional event to be easily tracked down.
NEVER use exceptions for control flow, illustrated with an
upsert example in the next four slides.
NEVER ‘Swallow’ exceptions, i.e. catch them and do nothing
with them.
Exception Handling
27. DECLARE @p int;
DECLARE c CURSOR FAST_FORWARD FOR
SELECT ProductID
FROM Sales.SalesOrderDetail;
OPEN c;
FETCH NEXT FROM c INTO @p;
WHILE @@FETCH_STATUS = 0
BEGIN
FETCH NEXT FROM c INTO @p;
/* Place the stored procedure to be tested
* on the line below.
*/
EXEC dbo.uspUpsert_V1 @p;
END;
CLOSE c;
DEALLOCATE c;
Exceptions Used For Flow Control
Test Harness
28. CREATE TABLE SalesByProduct (
ProductID int,
Sold int,
CONSTRAINT [PK_SalesByProduct]
(
ProductID
) ON [USERDATA]
) ON [USERDATA]
PRIMARY KEY CLUSTERED
Exceptions Used For Flow Control
‘Upsert’ Table
29. Execution time = 00:00:51.200
CREATE PROCEDURE uspUpsert_V1 (@ProductID
BEGIN
SET NOCOUNT ON;
int) AS
BEGIN TRY
INSERT INTO SalesByProduct
VALUES (@ProductID, 1);
END TRY
BEGIN CATCH
IF ERROR_NUMBER() = 2627
BEGIN
UPDATE
SET
WHERE
SalesByProduct
Sold += 1
ProductID = @ProductID;
END
END CATCH;
END;
‘Upsert’ Procedure First Attempt
30. Execution time = 00:00:20.080
CREATE PROCEDURE uspUpsert_V2 (@ProductID
BEGIN
SET NOCOUNT ON;
int) AS
UPDATE
SET
WHERE
SalesByProduct
Sold += 1
ProductID = @ProductID;
IF @@ROWCOUNT = 0
BEGIN
INSERT INTO SalesByProduct
VALUES (@ProductID, 1);
END;
END;
‘Upsert’ Procedure Second Attempt
31. With SQL Server 2008 onwards, consider using the MERGE
statement for upserts, execution time = 00:00:20.904
CREATE PROCEDURE uspUpsert_V3 (@ProductID int) AS
BEGIN
SET NOCOUNT ON;
MERGE
USING
AS
source
ON
SalesByProduct AS target
(SELECT @ProductID)
(ProductID)
(target.ProductID = source.ProductID)
WHEN MATCHED THEN
UPDATE
SET Sold += 1
WHEN NOT MATCHED THEN
INSERT (ProductID, Sold)
VALUES (source.ProductID, 1);
END;
‘Upsert’ Procedure Third Attempt
32. Scalar functions
this function:-
are another example of RBAR, consider
CREATE FUNCTION
RETURNS int
AS
BEGIN
udfMinProductQty ( @ProductID int )
RETURN ( SELECT
FROM
WHERE
MIN(OrderQty)
Sales.SalesOrderDetail
ProductId = @ProductID )
END;
RBAR and Scalar Functions
33. Now lets call the function from an example query:-
SELECT ProductId,
dbo.udfMinProductQty(ProductId)
FROM Production.Product
Elapsed time = 00:00:00.746
RBAR and Scalar Functions: Example
34. Now doing the same thing, but
valued function:-
using an inline table
CREATE FUNCTION tvfMinProductQty
@ProductId INT
)
RETURNS TABLE
AS
RETURN (
(
SELECT MAX(s.OrderQty) AS MinOrdQty
FROM Sales.SalesOrderDetail s
WHERE s.ProductId = @ProductId
)
RBAR and Scalar Functions A Better
Approach, Using Table Value Functions
35. Invoking the inline TVF from a query:-
SELECT ProductId,
(SELECT MinOrdQty
FROM dbo.tvfMinProductQty(ProductId)
FROM Production.Product
ORDER BY ProductId
) MinOrdQty
Elapsed time 00:00:00.330
RBAR and Scalar Functions A Better
Approach, Using Table Value Functions
36. Developing applications that use database
perform well depends on good:-
Schema design
Compiled statement plan reuse.
Connection management.
and
Minimizing the number of network round trips
between the database and the tier above.
Compiled Plan Reuse
37. Parameterise your queries in order to minimize compiling.
BUT, watch out for “Parameter sniffing”.
At runtime the database engine will sniff the values of the
parameters a query is compiled with and create a plan
accordingly.
Unfortunate when the values cause plans with table scans,
when the ‘Popular’ values lead to plans with index seeks.
Writing Plan Reuse Friendly Code
38. Use the RECOMPILE hint to force the creation of a new plan.
Use the optimise for hint in order for a plan to be created for
‘Popular’ values you specify.
Use the OPTIMISE FOR UNKNOWN hint, to cause a “General
purpose” plan to be created.
Copy parameters passed into a stored procedure to local
variables and use those in your query.
Parameter Sniffing
39. For OLTP style applications:-
Transactions will be short
Number of statements will be finite
SQL will only affect a few rows for each execution.
The SQL will be simple.
Plans will be skewed towards using index seeks over table scans.
Recompiles could double+ query execution time.
Therefore recompiles are undesirable for OLTP applications.
When (Re)Compiles
Are To Be Avoided
40. For OLAP style applications:-
Complex queries that may involve aggregation and analytic
SQL.
Queries may change constantly due to the use of reporting
and BI tools.
May involve WHERE clauses with potentially lots of
combinations of parameters.
Foregoing a recompile via OPTION(RECOMPILE) may be
worth taking a hit on for the benefit of a significant reduction
in total execution time.
This is the exception to the rule.
When Taking The Hit Of A
(Re)Compile Is Worthwhile
41. Be careful when using table variables.
Statistics cannot be gathered on these
The optimizer will assume they only contain one
row unless the statement is recompiled
This can lead to unexpected execution plans.
Table variables will always inhibit parallelism in
execution plans.
Table Variables
42. This applies to conditions in WHERE clauses.
If a WHERE clause condition can use an index, this is
said to be ‘Sargable’
A searchable argument
As a general rule of thumb the use of a function on a
column will suppress index usage.
i.e. WHERE ufn(MyColumn1) = <somevalue>
Sargability
43. Constructs that will always force a serial plan:-
All T-SQL user defined functions.
All CLR user defined functions with data access.
Built in function including: @@TRANCOUNT,
ERROR_NUMBER() and OBJECT_ID().
Dynamic cursors.
Be Aware Of Constructs That Create
Serial Regions In Execution Plans
44. Constructs that will always force a serial region within a plan:-
Table value functions
TOP
Recursive queries
Multi consumer spool
Sequence functions
System table scans
“Backwards” scans
Sequence functions
Global scalar aggregate
Be Aware Of Constructs That Create
Serial Regions In Execution Plans
45. Advise From The SQL Server
Optimizer Development Team
Craig Freedman, a former optimizer developer has
some good words of advice in his “Understanding
Query Processing and Query Plan in SQL Server”
slide deck.
The points on the next three slides
( quoted verbatim ) come from slide 40.
46. Watch Out For Errors In
Cardinality Estimates
Watch out for errors in cardinality estimates
Errors propagate upwards; look for the root cause
Make sure statistics are up to date and accurate
Avoid excessively complex predicates
Use computed columns for overly complex
expressions
47. General Tips
Use set based queries; (almost always) avoid cursors
Avoid joining columns with mismatched data types
Avoid unnecessary outer joins, cross applies, complex sub-queries,
dynamic index seeks, …
Avoid dynamic SQL
(but beware that sometimes dynamic SQL does yield a better plan)
Consider creating constraints
(but remember that there is a cost to maintain constraints)
If possible, use inline TVFs NOT multi-statement TVFs
Use SET STATISTICS IO ON to watch out for large numbers of
physical I/Os
Use indexes to workaround locking, concurrency, and deadlock
issues
48. OLTP and DW Tips
OLTP tips:
Avoid memory consuming or blocking iterators
Use seeks not scans
DW tips:
Use parallel plans
Watch out for skew in parallel plans
Avoid order preserving exchanges
49. • OLTP tips:
– Avoid memory consuming or blocking iterators
– Use seeks not scans
• DW tips:
– Use parallel plans
– Watch out for skew in parallel plans
– Avoid order preserving exchanges
51. Leverage functionality already
reinvent it, this will lead to:-
More robust code
Less development effort
Potentially faster code
Code with better readability
Easier to maintain code
in SQL Server, never
Avoid Reinventing The Wheel
52. This is furnishing the code with a facility to allow its execution
to be traced.
Write to a tracking table
And / or use xp_logevent to write to event log
DO NOT make the code a “Black box” which has to be dissected
statement by statement in production if it starts to fail.
Code Instrumentation
53. Make stored procedures and functions relatively single
minded in what they do.
Stored procedures and functions with lots of arguments are a
“Code smell” of code that:-
Is difficult to unit test with a high degree of confidence.
Does not lend itself to code reuse.
Smacks of poor design.
Favour Strong Functional
Independence For Code Artefacts
54.
Understand and use the full power of T-SQL.
Most people know how to UNION results sets together, but do not know
about INTERSECT and EXCEPT.
Also a lot of development effort can be saved by using T-SQL’s analytics
extensions where appropriate:-
RANK()
DENSE_RANK()
NTILE()
ROW_NUMBER()
LEAD() and LAG() (introduced in Denali)
Leverage The Full Power Of
Transact SQL
56. An ‘Ordinal’ in the context of the ORDER BY clause is when numbers are used to
represent column positions.
If the new columns are added or their order changed in the SELECT, this query will
return different results, potentially breaking the application using it.
SELECT TOP 5
[SalesOrderNumber]
,[OrderDate]
,[DueDate]
,[ShipDate]
,[Status]
FROM [AdventureWorks].[Sales].[SalesOrderHeader]
ORDER BY 2 DESC
Avoid Ordering By Ordinals
57. SELECT * retrieves all columns from a table
bad for performance if only a subset of these is
required.
Using columns by their names explicitly leads to
improved code readability.
Code is easier to maintain, as it enables the
“Developer” to see in situ what columns a query is
using.
Avoid SELECT *
58. A scenario that actually happened:-
A row is inserted into the customer table
Customer table has a primary key based on an identity
column
@@IDENTITY is used to obtain the key value of the customer
row inserted for the creation of an order row with a foreign
key linking back to customer.
The identity value obtained is nothing like the one for the
inserted row – why ?
Robust Code and @@IDENTITY
59. @@IDENTITY obtains the latest identity value
irrespective of the session it came from.
In the example the replication merge agent inserted
row in the customer table just before @@IDENTITY
was used.
The solution: always use SCOPE_IDENTITY() instead
of @@IDENTITY.
a
@@IDENTITY Is Dangerous !!!
60. SQL Tri State Logic
SQL has tri-state logic: TRUE, FALSE and NULL.
SQL data types cannot be compared to NULL using
conventional comparison operators:
<some value> <> NULL
<some value> > NULL
<some value> < NULL
<some value> = NULL
Always use IS NULL, IS NOT NULL, ISNULL and
COALESCE to handle NULLs correctly.
61. NULL Always Propagate
In Expressions
Expressions that includes NULL will always evaluate
to NULL, e.g.:
SELECT 1 + NULL
SELECT 1 – NULL
SELECT 1 * NULL
SELECT 1 / NULL
SELECT @MyString + NULL
If this is not the behaviour you want, code around
this using ISNULL or COALESCE.
62. Use Of The NOLOCK Hint
Historically SQL Server has always used locking to
enforce Isolation levels, however:
SQL Server ( 2005 onwards ) facilitates non
blocking versions of the read committed and
snapshot isolations levels through multi version
concurrency control (MVCC).
SQL Server 2014 which uses MVCC for its in
memory OLTP engine.
All Azure Database databases use the MVCC
version of read committed snapshot isolation.
63. Use Of The NOLOCK Hint
Objects can be scanned in two ways:
Allocation order, always applied to heaps, can
apply to indexes.
Logical order, indexes are traversed in logical leaf
node order.
Any queries against indexed tables (clustered or non-
clustered) using NOLOCK that are perform allocation-
ordered scans will be exposed to reading the same
data twice if another session causes the page to split
and the data to move during this process.
64. Use Of The NOLOCK Hint
If a session uses a NOLOCK hint on a heap / clustered
index, its reads would ignore any locks taken out on
pages/rows by in-flight transactions and
subsequently be able read uncommitted ( dirty )
data, if that row is in the process of being changed by
another session.
If the in-flight transaction rolls back, this leaves the
session in a state whereby it has read dirty data, i.e.
data that has been modified outside of a safe
transactional context.
Thanks to Mark Broadbent (@retracement) for
checking this and the last two slides.
65. Transaction Rollback Behaviour
CREATE TABLE Test (col1 INT)
BEGIN TRANSACTION
INSERT INTO Test VALUES (1);
UPDATE Test SET col1 = col1 + 1
WHERE 1/0 > 1;
COMMIT;
SELECT col1 FROM Test
-- ** 1 ** row is returned
CREATE TABLE Test (col1 INT)
SET XACT_ABORT ON
BEGIN TRANSACTION
INSERT INTO Test VALUES (1);
UPDATE Test SET col1 = col1 + 1
WHERE 1/0 > 1;
COMMIT;
SELECT col1 FROM Test
-- ** No rows ** are returned.
For SQL Server to automatically rollback an entire transaction
when a statement raises a run time error
SET XACT_ABORT must be set to ON.