SlideShare a Scribd company logo
1 of 20
Querying and Managing Data Using SQL Server 2005
Objectives


               In this session, you will learn to:
                  Manipulate data by using Data Manipulation Language
                  statements
                  Manipulate the Extensible Markup Language data




    Ver. 1.0                        Session 8                           Slide 1 of 20
Querying and Managing Data Using SQL Server 2005
Storing Data in a Table


                Data can be stored in a table:
                   By adding data in the form of rows
                   By using the INSERT statement
                   Syntax:
                    INSERT [INTO] {table_name} [(column_list)]
                    VALUES {DEFAULT | values_list |
                    select_statement}
                Let’s see how…




     Ver. 1.0                       Session 8              Slide 2 of 20
Querying and Managing Data Using SQL Server 2005
Storing Data in a Table (Contd.)


                Data can be inserted in a table in the following ways:
                   By inserting partial data
                   By inserting data in related tables
                   By copying data from an existing table into a new table
                Let’s see how…




     Ver. 1.0                        Session 8                               Slide 3 of 20
Querying and Managing Data Using SQL Server 2005
Just a minute


               Which statement allows you to insert data in a table?




               Answer:
                   INSERT INTO




    Ver. 1.0                      Session 8                            Slide 4 of 20
Querying and Managing Data Using SQL Server 2005
Just a minute


               Which statement allows you to copy contents of one table
               into another table?




               Answer:
                  SELECT INTO




    Ver. 1.0                      Session 8                       Slide 5 of 20
Querying and Managing Data Using SQL Server 2005
Updating Data in a Table


               Data in a table can be updated:
                  When there is a change in the data
                  By using the UPDATE statement
                  Syntax:
                   UPDATE table_name
                   SET column_name = value [, column_name =
                   value]
                   [FROM table_name]
                   [WHERE condition]
               Let’s see how…




    Ver. 1.0                      Session 8               Slide 6 of 20
Querying and Managing Data Using SQL Server 2005
Just a minute


               Which statement allows you to modify data in a database?




               Answer:
                  UPDATE




    Ver. 1.0                      Session 8                       Slide 7 of 20
Querying and Managing Data Using SQL Server 2005
Deleting Data from a Table


               Data in a table can be deleted :
                  When the data is no longer required
                  By using the DELETE statement
                  Syntax:
                   DELETE [FROM] table_name
                   FROM table(s)]
                   WHERE condition]
               Let’s see how…




    Ver. 1.0                       Session 8            Slide 8 of 20
Querying and Managing Data Using SQL Server 2005
Deleting Data from a Table (Contd.)


               While deleting data from related tables:
                  Ensure that first the records are deleted from the table that
                  contains foreign key and then from the table that contains the
                  primary key
               Delete all records from a table:
                  Using the DELETE statement or the TRUNCATE TABLE
                  statement
                  Syntax:
                   TRUNCATE TABLE table_name
               Let’s see how…




    Ver. 1.0                        Session 8                             Slide 9 of 20
Querying and Managing Data Using SQL Server 2005
Just a minute


               Which statement allows you to delete a single row from a
               table?




               Answer:
                  DELETE table_name




    Ver. 1.0                      Session 8                       Slide 10 of 20
Querying and Managing Data Using SQL Server 2005
Demo: Manipulating Data in Tables


                Problem Statement:
                   You are the database developer in AdventureWorks, Inc. As a
                   part of the regular database operations, you need to
                   implement the following changes in the AdventureWorks
                   database:
                    1. The management has decided to create a new department named
                       Inventory Control under the Inventory Management group. You
                       need to add the details of this new department into the
                       Department table. The details should adhere to the structure of the
                       Department table.
                    2. Change the department names for the following employees to the
                       Inventory Control department:
                              Vamsi N. kuppa
                              Susan W. Eaton
                   The Department ID of the Inventory Control department is 17.



     Ver. 1.0                         Session 8                                 Slide 11 of 20
Querying and Managing Data Using SQL Server 2005
Demo: Manipulating Data in Tables (Contd.)


                Solution:
                    To solve the preceding problem, you need to perform the
                    following tasks:
                     1. Insert a new record in the Department table.
                     2. Update the employee details to change the department.
                     3. Verify that data is inserted and modified.




     Ver. 1.0                         Session 8                                 Slide 12 of 20
Querying and Managing Data Using SQL Server 2005
Storing XML Data in a Table


                Flash presentation: Introduction to XML
                Store XML data in a table:
                   By using XML data type
                   By transforming XML data into a rowset




     Ver. 1.0                       Session 8               Slide 13 of 20
Querying and Managing Data Using SQL Server 2005
Storing XML Data in a Table (Contd.)


                Storing XML data in a rowset involves the following tasks:
                 1.   Parsing the XML document.
                 2.   Retrieving a rowset from the tree.
                 3.   Storing the data from the rowset.
                 4.   Clearing the memory.
                Let’s see how…




     Ver. 1.0                           Session 8                    Slide 14 of 20
Querying and Managing Data Using SQL Server 2005
Retrieving the XML Data from a Table


                Involves extracting data from a table in the form of well-
                formed XML fragments
                Is performed by using:
                   FOR XML clause in the SELECT statement
                   XQuery language




     Ver. 1.0                       Session 8                          Slide 15 of 20
Querying and Managing Data Using SQL Server 2005
Retrieving the XML Data from a Table (Contd.)


                FOR XML:
                   Retrieves the XML data using the following directives:
                    • RAW: Is used to return an xml file with each row representing an
                      XML element
                    • AUTO: Is used to return query results as nested XML elements
                    • PATH: Is used to return specific values by specifying the column
                      names for which you need to return the data
                    • EXPLICIT: Is used to return an XML file that gets the format as
                      specified in the SELECT statement
                Let’s see how…




     Ver. 1.0                         Session 8                               Slide 16 of 20
Querying and Managing Data Using SQL Server 2005
Just a minute


               Which clause is used to extract data from a table in the XML
               format?




               Answer:
                   FOR XML clause is used to extract data from a table in
                   the XML format.



    Ver. 1.0                        Session 8                           Slide 17 of 20
Querying and Managing Data Using SQL Server 2005
Modifying XML Data


               Is performed by using the modify function, which allows to
               perform the following operations:
                  Insert: Used to add nodes to XML in an XML column or
                  variable
                  Replace: Used to update the XML data
                  Delete: Used to remove a node from the XML data
               Let’s see how…




    Ver. 1.0                       Session 8                         Slide 18 of 20
Querying and Managing Data Using SQL Server 2005
Summary


              In this session, you learned that:
                 The INSERT statement is used to insert data into the table.
                 While inserting data into a table, the data type of the
                 information must match the data types of the columns of the
                 table.
                 It is not essential to insert data into a column that allows NULL
                 or has a default constraint assigned to it.
                 You can copy contents from one table into another table by
                 using the SELECT INTO command.
                 The SQL Server provides a row update statement called
                 UPDATE to modify values within tables.




   Ver. 1.0                        Session 8                              Slide 19 of 20
Querying and Managing Data Using SQL Server 2005
Summary (Contd.)


               You can delete a row from a table by using the DELETE
               statement.
               You use the TRUNCATE TABLE statement to remove all the
               rows from a table.
               SQL Server 2005 uses XML as a data type to save the XML
               data in its original state.
               The SQL Server allows you to shred the XML data by using the
               OPENXML statement.
               You can use the FOR XML clause of the SELECT statement to
               retrieve the XML data in different ways by using the RAW,
               AUTO, PATH, EXPLICIT modes.
               You can modify the XML data by using the modify function
               provided by the XML data type.
               Using the modify function, you can insert, update, or remove
               a node from the XML data.


    Ver. 1.0                    Session 8                          Slide 20 of 20

More Related Content

What's hot

What's hot (18)

Using T-SQL
Using T-SQL Using T-SQL
Using T-SQL
 
11 qmds2005 session16
11 qmds2005 session1611 qmds2005 session16
11 qmds2005 session16
 
SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3
SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3
SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3
 
SQL
SQLSQL
SQL
 
Oracle sql material
Oracle sql materialOracle sql material
Oracle sql material
 
Dbms lab Manual
Dbms lab ManualDbms lab Manual
Dbms lab Manual
 
Advanced MySQL Query Optimizations
Advanced MySQL Query OptimizationsAdvanced MySQL Query Optimizations
Advanced MySQL Query Optimizations
 
Navicat en
Navicat enNavicat en
Navicat en
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
 
Including Constraints -Oracle Data base
Including Constraints -Oracle Data base Including Constraints -Oracle Data base
Including Constraints -Oracle Data base
 
View & index in SQL
View & index in SQLView & index in SQL
View & index in SQL
 
MySQL Replication Evolution -- Confoo Montreal 2017
MySQL Replication Evolution -- Confoo Montreal 2017MySQL Replication Evolution -- Confoo Montreal 2017
MySQL Replication Evolution -- Confoo Montreal 2017
 
Sql views
Sql viewsSql views
Sql views
 
Oracle Data Redaction
Oracle Data RedactionOracle Data Redaction
Oracle Data Redaction
 
Assg2 b 19121033-converted
Assg2 b 19121033-convertedAssg2 b 19121033-converted
Assg2 b 19121033-converted
 
SQL200.3 Module 3
SQL200.3 Module 3SQL200.3 Module 3
SQL200.3 Module 3
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
SQL Server Views
SQL Server ViewsSQL Server Views
SQL Server Views
 

Viewers also liked

Viewers also liked (6)

Informe 720
Informe 720Informe 720
Informe 720
 
Busqueda de informacion en internet
Busqueda de informacion en internetBusqueda de informacion en internet
Busqueda de informacion en internet
 
Comunicato 30
Comunicato 30Comunicato 30
Comunicato 30
 
Sunscreen
SunscreenSunscreen
Sunscreen
 
Third eye designers
Third eye designersThird eye designers
Third eye designers
 
04 qmds2005 session05
04 qmds2005 session0504 qmds2005 session05
04 qmds2005 session05
 

Similar to 06 qmds2005 session08

03 qmds2005 session03
03 qmds2005 session0303 qmds2005 session03
03 qmds2005 session03Niit Care
 
05 qmds2005 session07
05 qmds2005 session0705 qmds2005 session07
05 qmds2005 session07Niit Care
 
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptxMy lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptxEliasPetros
 
New features of sql server 2005
New features of sql server 2005New features of sql server 2005
New features of sql server 2005Govind Raj
 
Sql server ___________session 1(sql 2008)
Sql server  ___________session 1(sql 2008)Sql server  ___________session 1(sql 2008)
Sql server ___________session 1(sql 2008)Ehtisham Ali
 
SQL_SERVER_BASIC_1_Training.pptx
SQL_SERVER_BASIC_1_Training.pptxSQL_SERVER_BASIC_1_Training.pptx
SQL_SERVER_BASIC_1_Training.pptxKashifManzoorMeo
 
Introduction4 SQLite
Introduction4 SQLiteIntroduction4 SQLite
Introduction4 SQLiteStanley Huang
 
mysql 1st. act.
mysql 1st. act.mysql 1st. act.
mysql 1st. act.von lozano
 
Introduction to Oracle Database.pptx
Introduction to Oracle Database.pptxIntroduction to Oracle Database.pptx
Introduction to Oracle Database.pptxSiddhantBhardwaj26
 
SQL_SERVER_BASIC_1_Training.pptx
SQL_SERVER_BASIC_1_Training.pptxSQL_SERVER_BASIC_1_Training.pptx
SQL_SERVER_BASIC_1_Training.pptxQuyVo27
 
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptxhjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptxEliasPetros
 
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...SakkaravarthiS1
 
Introduction to Structured Query Language (SQL).ppt
Introduction to Structured Query Language (SQL).pptIntroduction to Structured Query Language (SQL).ppt
Introduction to Structured Query Language (SQL).pptAshwini Rao
 
An introduction to new data warehouse scalability features in sql server 2008
An introduction to new data warehouse scalability features in sql server 2008An introduction to new data warehouse scalability features in sql server 2008
An introduction to new data warehouse scalability features in sql server 2008Klaudiia Jacome
 
Page 5 of 7Delete this text and type your name hereThis fi.docx
Page 5 of 7Delete this text and type your name hereThis fi.docxPage 5 of 7Delete this text and type your name hereThis fi.docx
Page 5 of 7Delete this text and type your name hereThis fi.docxalfred4lewis58146
 
Dms 22319 micro project
Dms 22319 micro projectDms 22319 micro project
Dms 22319 micro projectARVIND SARDAR
 

Similar to 06 qmds2005 session08 (20)

03 qmds2005 session03
03 qmds2005 session0303 qmds2005 session03
03 qmds2005 session03
 
05 qmds2005 session07
05 qmds2005 session0705 qmds2005 session07
05 qmds2005 session07
 
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptxMy lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
 
New features of sql server 2005
New features of sql server 2005New features of sql server 2005
New features of sql server 2005
 
Sql server ___________session 1(sql 2008)
Sql server  ___________session 1(sql 2008)Sql server  ___________session 1(sql 2008)
Sql server ___________session 1(sql 2008)
 
SQL_SERVER_BASIC_1_Training.pptx
SQL_SERVER_BASIC_1_Training.pptxSQL_SERVER_BASIC_1_Training.pptx
SQL_SERVER_BASIC_1_Training.pptx
 
Introduction4 SQLite
Introduction4 SQLiteIntroduction4 SQLite
Introduction4 SQLite
 
mysql 1st. act.
mysql 1st. act.mysql 1st. act.
mysql 1st. act.
 
Introduction to Oracle Database.pptx
Introduction to Oracle Database.pptxIntroduction to Oracle Database.pptx
Introduction to Oracle Database.pptx
 
SQL_SERVER_BASIC_1_Training.pptx
SQL_SERVER_BASIC_1_Training.pptxSQL_SERVER_BASIC_1_Training.pptx
SQL_SERVER_BASIC_1_Training.pptx
 
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptxhjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
 
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
 
Introduction to Structured Query Language (SQL).ppt
Introduction to Structured Query Language (SQL).pptIntroduction to Structured Query Language (SQL).ppt
Introduction to Structured Query Language (SQL).ppt
 
chapter 8 SQL.ppt
chapter 8 SQL.pptchapter 8 SQL.ppt
chapter 8 SQL.ppt
 
SQL Query
SQL QuerySQL Query
SQL Query
 
Sql
SqlSql
Sql
 
An introduction to new data warehouse scalability features in sql server 2008
An introduction to new data warehouse scalability features in sql server 2008An introduction to new data warehouse scalability features in sql server 2008
An introduction to new data warehouse scalability features in sql server 2008
 
Presentation1
Presentation1Presentation1
Presentation1
 
Page 5 of 7Delete this text and type your name hereThis fi.docx
Page 5 of 7Delete this text and type your name hereThis fi.docxPage 5 of 7Delete this text and type your name hereThis fi.docx
Page 5 of 7Delete this text and type your name hereThis fi.docx
 
Dms 22319 micro project
Dms 22319 micro projectDms 22319 micro project
Dms 22319 micro project
 

More from Niit Care (20)

Ajs 1 b
Ajs 1 bAjs 1 b
Ajs 1 b
 
Ajs 4 b
Ajs 4 bAjs 4 b
Ajs 4 b
 
Ajs 4 a
Ajs 4 aAjs 4 a
Ajs 4 a
 
Ajs 4 c
Ajs 4 cAjs 4 c
Ajs 4 c
 
Ajs 3 b
Ajs 3 bAjs 3 b
Ajs 3 b
 
Ajs 3 a
Ajs 3 aAjs 3 a
Ajs 3 a
 
Ajs 3 c
Ajs 3 cAjs 3 c
Ajs 3 c
 
Ajs 2 b
Ajs 2 bAjs 2 b
Ajs 2 b
 
Ajs 2 a
Ajs 2 aAjs 2 a
Ajs 2 a
 
Ajs 2 c
Ajs 2 cAjs 2 c
Ajs 2 c
 
Ajs 1 a
Ajs 1 aAjs 1 a
Ajs 1 a
 
Ajs 1 c
Ajs 1 cAjs 1 c
Ajs 1 c
 
Dacj 4 2-c
Dacj 4 2-cDacj 4 2-c
Dacj 4 2-c
 
Dacj 4 2-b
Dacj 4 2-bDacj 4 2-b
Dacj 4 2-b
 
Dacj 4 2-a
Dacj 4 2-aDacj 4 2-a
Dacj 4 2-a
 
Dacj 4 1-c
Dacj 4 1-cDacj 4 1-c
Dacj 4 1-c
 
Dacj 4 1-b
Dacj 4 1-bDacj 4 1-b
Dacj 4 1-b
 
Dacj 4 1-a
Dacj 4 1-aDacj 4 1-a
Dacj 4 1-a
 
Dacj 1-2 b
Dacj 1-2 bDacj 1-2 b
Dacj 1-2 b
 
Dacj 1-3 c
Dacj 1-3 cDacj 1-3 c
Dacj 1-3 c
 

Recently uploaded

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 

Recently uploaded (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

06 qmds2005 session08

  • 1. Querying and Managing Data Using SQL Server 2005 Objectives In this session, you will learn to: Manipulate data by using Data Manipulation Language statements Manipulate the Extensible Markup Language data Ver. 1.0 Session 8 Slide 1 of 20
  • 2. Querying and Managing Data Using SQL Server 2005 Storing Data in a Table Data can be stored in a table: By adding data in the form of rows By using the INSERT statement Syntax: INSERT [INTO] {table_name} [(column_list)] VALUES {DEFAULT | values_list | select_statement} Let’s see how… Ver. 1.0 Session 8 Slide 2 of 20
  • 3. Querying and Managing Data Using SQL Server 2005 Storing Data in a Table (Contd.) Data can be inserted in a table in the following ways: By inserting partial data By inserting data in related tables By copying data from an existing table into a new table Let’s see how… Ver. 1.0 Session 8 Slide 3 of 20
  • 4. Querying and Managing Data Using SQL Server 2005 Just a minute Which statement allows you to insert data in a table? Answer: INSERT INTO Ver. 1.0 Session 8 Slide 4 of 20
  • 5. Querying and Managing Data Using SQL Server 2005 Just a minute Which statement allows you to copy contents of one table into another table? Answer: SELECT INTO Ver. 1.0 Session 8 Slide 5 of 20
  • 6. Querying and Managing Data Using SQL Server 2005 Updating Data in a Table Data in a table can be updated: When there is a change in the data By using the UPDATE statement Syntax: UPDATE table_name SET column_name = value [, column_name = value] [FROM table_name] [WHERE condition] Let’s see how… Ver. 1.0 Session 8 Slide 6 of 20
  • 7. Querying and Managing Data Using SQL Server 2005 Just a minute Which statement allows you to modify data in a database? Answer: UPDATE Ver. 1.0 Session 8 Slide 7 of 20
  • 8. Querying and Managing Data Using SQL Server 2005 Deleting Data from a Table Data in a table can be deleted : When the data is no longer required By using the DELETE statement Syntax: DELETE [FROM] table_name FROM table(s)] WHERE condition] Let’s see how… Ver. 1.0 Session 8 Slide 8 of 20
  • 9. Querying and Managing Data Using SQL Server 2005 Deleting Data from a Table (Contd.) While deleting data from related tables: Ensure that first the records are deleted from the table that contains foreign key and then from the table that contains the primary key Delete all records from a table: Using the DELETE statement or the TRUNCATE TABLE statement Syntax: TRUNCATE TABLE table_name Let’s see how… Ver. 1.0 Session 8 Slide 9 of 20
  • 10. Querying and Managing Data Using SQL Server 2005 Just a minute Which statement allows you to delete a single row from a table? Answer: DELETE table_name Ver. 1.0 Session 8 Slide 10 of 20
  • 11. Querying and Managing Data Using SQL Server 2005 Demo: Manipulating Data in Tables Problem Statement: You are the database developer in AdventureWorks, Inc. As a part of the regular database operations, you need to implement the following changes in the AdventureWorks database: 1. The management has decided to create a new department named Inventory Control under the Inventory Management group. You need to add the details of this new department into the Department table. The details should adhere to the structure of the Department table. 2. Change the department names for the following employees to the Inventory Control department: Vamsi N. kuppa Susan W. Eaton The Department ID of the Inventory Control department is 17. Ver. 1.0 Session 8 Slide 11 of 20
  • 12. Querying and Managing Data Using SQL Server 2005 Demo: Manipulating Data in Tables (Contd.) Solution: To solve the preceding problem, you need to perform the following tasks: 1. Insert a new record in the Department table. 2. Update the employee details to change the department. 3. Verify that data is inserted and modified. Ver. 1.0 Session 8 Slide 12 of 20
  • 13. Querying and Managing Data Using SQL Server 2005 Storing XML Data in a Table Flash presentation: Introduction to XML Store XML data in a table: By using XML data type By transforming XML data into a rowset Ver. 1.0 Session 8 Slide 13 of 20
  • 14. Querying and Managing Data Using SQL Server 2005 Storing XML Data in a Table (Contd.) Storing XML data in a rowset involves the following tasks: 1. Parsing the XML document. 2. Retrieving a rowset from the tree. 3. Storing the data from the rowset. 4. Clearing the memory. Let’s see how… Ver. 1.0 Session 8 Slide 14 of 20
  • 15. Querying and Managing Data Using SQL Server 2005 Retrieving the XML Data from a Table Involves extracting data from a table in the form of well- formed XML fragments Is performed by using: FOR XML clause in the SELECT statement XQuery language Ver. 1.0 Session 8 Slide 15 of 20
  • 16. Querying and Managing Data Using SQL Server 2005 Retrieving the XML Data from a Table (Contd.) FOR XML: Retrieves the XML data using the following directives: • RAW: Is used to return an xml file with each row representing an XML element • AUTO: Is used to return query results as nested XML elements • PATH: Is used to return specific values by specifying the column names for which you need to return the data • EXPLICIT: Is used to return an XML file that gets the format as specified in the SELECT statement Let’s see how… Ver. 1.0 Session 8 Slide 16 of 20
  • 17. Querying and Managing Data Using SQL Server 2005 Just a minute Which clause is used to extract data from a table in the XML format? Answer: FOR XML clause is used to extract data from a table in the XML format. Ver. 1.0 Session 8 Slide 17 of 20
  • 18. Querying and Managing Data Using SQL Server 2005 Modifying XML Data Is performed by using the modify function, which allows to perform the following operations: Insert: Used to add nodes to XML in an XML column or variable Replace: Used to update the XML data Delete: Used to remove a node from the XML data Let’s see how… Ver. 1.0 Session 8 Slide 18 of 20
  • 19. Querying and Managing Data Using SQL Server 2005 Summary In this session, you learned that: The INSERT statement is used to insert data into the table. While inserting data into a table, the data type of the information must match the data types of the columns of the table. It is not essential to insert data into a column that allows NULL or has a default constraint assigned to it. You can copy contents from one table into another table by using the SELECT INTO command. The SQL Server provides a row update statement called UPDATE to modify values within tables. Ver. 1.0 Session 8 Slide 19 of 20
  • 20. Querying and Managing Data Using SQL Server 2005 Summary (Contd.) You can delete a row from a table by using the DELETE statement. You use the TRUNCATE TABLE statement to remove all the rows from a table. SQL Server 2005 uses XML as a data type to save the XML data in its original state. The SQL Server allows you to shred the XML data by using the OPENXML statement. You can use the FOR XML clause of the SELECT statement to retrieve the XML data in different ways by using the RAW, AUTO, PATH, EXPLICIT modes. You can modify the XML data by using the modify function provided by the XML data type. Using the modify function, you can insert, update, or remove a node from the XML data. Ver. 1.0 Session 8 Slide 20 of 20

Editor's Notes

  1. Begin the session by sharing the session objectives with the students.
  2. In this slide, you will teach the students how to store data in a table by using the INSERT statement. You need to explain the various ways in which data can be inserted with the example given in the Student Guide: You can demonstrate the examples, by executing the following statements: To insert a row into the Address table with all the column values, you can use the following statements: INSERT Address VALUES (104, '24, Herbon Apts', 'Arthor Lane', 56, '607009') Or INSERT Address (AddressID, AddressLine1, AddressLine2, StateProvinceID, PostalCode) VALUES (104, '24, Herbon Apts',’ Arthor Lane’,56, ‘607009’) Or INSERT Address (AddressID, AddressLine1, AddressLine2, PostalCode, StateProvinceID) VALUES (104, '24, Herbon Apts',’ Arthor Lane’, ‘607009’, 56) NOTE: Before executing the preceding statements, you need to create the Address table. For this, execute the database script named CreateAddressTable.sql present in the Chapter 5\\Instep folder of the TIRM CD. Guidelines to Inserting Data While inserting rows into a table, explain to the students that values for columns containing the char and varchar data types should be enclosed in single quotes. While inserting values into a column that has a default constraint defined on it, if you want the default value to be inserted for that column, you can use the DEFAULT keyword. While entering data, the column-list needs to be specified when the data being entered is not in the order of the columns in the table or when the data is not being entered for all the columns. The SQL Server will automatically generate values for an Identity column. It is not a good practice to insert values for the column. While inserting partial data, the columns for which data is not being inserted should support NULL or default values. You cannot insert rows into two tables with a single INSERT statement. Example:
  3. Additional Inputs While inserting rows, it is a good practice to mention the column list.
  4. Reiterate the concepts taught earlier by asking the given question.
  5. Reiterate the concepts taught earlier by asking eh given question.
  6. Updating Rows Explain to the students that whenever data is updated, the modified value should adhere to the business rules that were effective when the row was entered. In addition, inform the students that you cannot update columns from two different tables with a single UPDATE statement.
  7. Reiterate the concepts taught earlier by asking the given question.
  8. Explain the students that whenever Delete statement should be used only in the case when the data is highly redundant. You cannot delete rows from two different tables using a single DELETE statement.
  9. Explain to the students that the WHERE clause cannot be used in the TRUNCATE TABLE statement as it is used to remove all the data from the table. Additional Input The TRUNCATE TABLE command deletes data from a table page wise and this operation is not logged in the transaction log. This is the reason a delete operation in a transaction can be rolled back, but a TRUNCATE TABLE command cannot be rolled back. Transactions are dealt with in detail later in the course. FAQs Question : What is the difference between the DELETE and TRUNCATE statements? Answer : The DELETE statement is used to delete specific rows from a table, whereas the TRUNCATE statement is used to delete all the rows from a table.
  10. Reiterate the concepts taught earlier by asking the given question.
  11. You need to ensure that at the end of this demo, the students are able to modify the data present in a table.
  12. Input: Before showing this presentation, ensure that all the Flash presentations have been copied to the C:\\SQL Flash Presentations folder. Input for the Flash Presentation: Screen 1: Screen 2: Explain to the students that a database server is accessed by various clients. These clients include desktop applications, Web applications, and mobile applications. The relational data might not be suitable for all types of applications, as a mobile application is unable to access data directly from the SQL Server. Therefore, a mechanism is required that ensures the data can be accessed by any client using any hardware or software platform. Screen 3: Explain to the students that the SQL Server allows the database developers to store the data in the XML format, which enables the data to be accessed by any client. Now even mobile applications are able to retrieve the data from the SQL Server. Screen 4: Explain the various components of the XML document to the students.
  13. In this topic, you need to teach the students only about XML. You need not give details of schema and XQuery. You can inform the students that they will not be marked based on XQuery and schema in their MT. Additional Input Unlike the previous versions of SQL Server, now you can store XML data in the SQL Server itself. You can use the XML data type to store the XML data in a table. You can use the XQUERY expressions to query the XML snippet stored in the table.
  14. CG Input: While teaching the students how to store and retrieve XML data, you need to demonstrate the examples given in the chapter. For the demonstration, you can use the data files present in the TIRM CD to create the required database objects or files. Before showing the example, execute the CreateTable.SQL database script , present in the Chapter 5\\Instep folder of the TIRM CD. Use CustomerDetails.xml for the XML snippet .
  15. Refer SG for detail explanation of the examples
  16. Reiterate the concepts taught earlier by asking the given question.
  17. In the chapter, an activity has been given to save data in an XML column. You do not need to demonstrate this activity in the class. You can handle the class by saying that they will not be judged on the concept in their MT.
  18. You can summarize the session with the help of the Summary given in the SG. In addition, you can ask the students to summarize what they have learned in this session.
  19. You can summarize the session with the help of the Summary given in the SG. In addition, you can ask the students to summarize what they have learned in this session.