09 | Modifying Data Graeme Malcolm | Senior Content Developer, Microsoft Geoff Allix | Principal Technologist, Content Master.

Slides:



Advertisements
Similar presentations
CC SQL Utilities.
Advertisements

Virtual training week 4 structured query language (SQL)
Fundamentals, Design, and Implementation, 9/e Chapter 11 Managing Databases with SQL Server 2000.
Chapter 5 Data Manipulation and Transaction Control Oracle 10g: SQL
SQL Basics. SQL SQL (Structured Query Language) is a special-purpose programming language designed from managing data in relational database management.
Graeme Malcolm | Senior Content Developer, Microsoft Geoff Allix | Principal Technologist, Content Master.
Module 11: Programming Across Multiple Servers. Overview Introducing Distributed Queries Setting Up a Linked Server Environment Working with Linked Servers.
Other database objects (Sequence). What Is a Sequence? A sequence: Automatically generates sequential numbers Is a sharable object Is typically used to.
Module 3: Creating Data Types and Tables. Overview Working with Data Types Working with Tables Generating Column Values Generating Scripts.
10 | Programming with Transact-SQL Graeme Malcolm | Senior Content Developer, Microsoft Geoff Allix | Principal Technologist, Content Master.
Module 3 Designing and Implementing Tables. Module Overview Designing Tables Working with Schemas Creating and Altering Tables.
Database Lab Lecture 1. Database Languages Data definition language ( DDL ) Data definition language –defines data types and the relationships among them.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
06 | Modifying Data in SQL Server Brian Alderman | MCT, CEO / Founder of MicroTechPoint Tobias Ternstrom | Microsoft SQL Server Program Manager.
Database Programming Sections 11 & 12 –Sequences, Indexes, and Synonymns.
IMS 4212: Data Manipulation 1 Dr. Lawrence West, MIS Dept., University of Central Florida Additional Data Manipulation Statements INSERT.
Module 7: Modifying Data. Overview Using Transactions Inserting Data Deleting Data Updating Data Performance Considerations.
SQL CREATING AND MANAGING TABLES lecture4 1. Database Objects ObjectDescription TableBasic unit of storage; composed of rows and columns ViewLogically.
SQL ACTION QUERIES AND TRANSACTION CONTROL CS 260 Database Systems.
Constraints Lesson 8. Skills Matrix Constraints Domain Integrity: A domain refers to a column in a table. Domain integrity includes data types, rules,
Session 1 Module 1: Introduction to Data Integrity
Altering Tables and Constraints Database Systems Objectives Add and modify columns. Add, enable, disable, or remove constraints. Drop a table. Remove.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
Module 3: Using XML. Overview Retrieving XML by Using FOR XML Shredding XML by Using OPENXML Introducing XQuery Using the xml Data Type.
Database Programming Sections 12 – Sequences, Indexes, and Synonymns.
DML Statements contd.. SQL Server CURSORS Cursor is used in handling results of select query for data calculations Cursors are used as buffered.
Oracle 10g Database Administrator: Implementation and Administration Chapter 10 Basic Data Management.
1 CS 430 Database Theory Winter 2005 Lecture 13: SQL DML - Modifying Data.
Module 10 Merging Data and Passing Tables. Module Overview Using the MERGE Statement Implementing Table Types Using Table Types As Parameters.
1 Database Fundamentals Introduction to SQL. 2 SQL Overview Structured Query Language The standard for relational database management systems (RDBMS)
Oracle 11g: SQL Chapter 5 Data Manipulation and Transaction Control.
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
Chapter 12 Introducing Databases. Objectives What a database is and which databases are typically used with ASP.NET pages What SQL is, how it looks, and.
Querying with Transact-SQL
Fundamentals of DBMS Notes-1.
Database Access with SQL
Structured Query Language
Using DML to Modify Data
The Basics of Data Manipulation
Insert, Update and the rest…
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
© 2016, Mike Murach & Associates, Inc.
11 | Error Handling and Transactions
SQL Creating and Managing Tables
10 | Programming with Transact-SQL
Data Definition and Data Types
09 | Modifying Data Graeme Malcolm | Senior Content Developer, Microsoft Geoff Allix | Principal Technologist, Content Master.
05 | Using Functions and Aggregating Data
03 | Querying Multiple Tables with Joins
08 | Grouping Sets and Pivoting Data
Module 5: Implementing Data Integrity by Using Constraints
06 | Using Subqueries and APPLY
04 | Using Set Operators Graeme Malcolm | Senior Content Developer, Microsoft Geoff Allix | Principal Technologist, Content Master.
20761B 12: Using Set Operators Module 12   Using Set Operators.
SQL Creating and Managing Tables
Writing SELECT Queries
02 | Querying Tables with SELECT
07 | Using Table Expressions
SQL Creating and Managing Tables
Lecturer: Mukhtar Mohamed Ali “Hakaale”
Chapter 5 Sequences.
The Basics of Data Manipulation
Chapter 4 Indexes.
CH 4 Indexes.
CH 4 Indexes.
Contents Preface I Introduction Lesson Objectives I-2
Chapter 8 Advanced SQL.
Chapter 11 Managing Databases with SQL Server 2000
Using DML to Modify Data
02 | Querying Tables with SELECT
Presentation transcript:

09 | Modifying Data Graeme Malcolm | Senior Content Developer, Microsoft Geoff Allix | Principal Technologist, Content Master

Module Overview Inserting Data into Tables Generating Identifiers Updating Data in Tables Deleting Data in Tables

Inserting Data into Tables INSERT…VALUES Inserts explicit values You can omit identity columns, columns that allow NULL, and columns with default constraints. You can also explicitly specify NULL and DEFAULT INSERT…SELECT / INSERT…EXEC Inserts the results returned by the query or stored procedure into an existing table SELECT…INTO Creates a new table from the results of a query Not currently supported in Azure SQL Database

Generating Identifiers Using Identity Columns IDENTITY property of a column generates sequential numbers automatically for insertion into a table Can specify optional seed and increment values Use system variables and functions to return last inserted identity: @@IDENTITY: The last identity generated in the session SCOPE_IDENTITY(): The last identity generated in the current scope IDENT_CURRENT('<table_name>'): The last identity inserted into a table INSERT INTO Sales.Orders (CustomerID, Amount) VALUES (12, 2056.99); … SELECT SCOPE_IDENTITY() AS OrderID;

Generating Identifiers Using Sequences Sequences are objects that generate sequential numbers Supported in SQL Server 2012 and later Exist independently of tables, so offer greater flexibility than Identity Use SELECT NEXT VALUE FOR to retrieve the next sequential number Can be set as the default value for a column CREATE SEQUENCE Sales.OrderNumbers AS INT STARTS WITH 1 INCREMENT BY 1; … SELECT NEXT VALUE FOR Sales.OrderNumbers;

Inserting Data into Tables

Updating Data in a Table The UPDATE Statement Updates all rows in a table or view Set can be filtered with a WHERE clause Set can be defined with a FROM clause Only columns specified in the SET clause are modified UPDATE Production.Product SET unitprice = (unitprice * 1.04) WHERE categoryid = 1 AND discontinued = 0;

Updating Data in a Table The MERGE Statement MERGE modifies data based on a condition When the source matches the target When the source has no match in the target When the target has no match in the source MERGE INTO Production.Products as P USING Production.ProductsStaging as S ON P.ProductID=S.ProductID WHEN MATCHED THEN UPDATE SET P.UnitPrice = S.UnitPrice, P.Discontinued=S.Discontinued WHEN NOT MATCHED THEN INSERT (ProductName, CategoryID, UnitPrice, Discontinued) VALUES (S.ProductName, S.CategoryID, S.UnitPrice, S.Discontinued);

Deleting Data From a Table DELETE without a WHERE clause deletes all rows Use a WHERE clause to delete specific rows TRUNCATE TABLE clears the entire table Storage physically deallocated, rows not individually removed Minimally logged Can be rolled back if TRUNCATE issued within a transaction TRUNCATE TABLE Will fail if the table is referenced by a foreign key constraint in another table DELETE FROM Sales.OrderDetails WHERE orderid = 10248;

Updating and Deleting Data

Modifying Data Inserting Data into Tables Generating Identifiers Updating Data in Tables Deleting Data in Tables Lab: Modifying Data