1. Trang chủ
  2. » Công Nghệ Thông Tin

Instructor Inputs - Session 7 doc

16 151 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 16
Dung lượng 908,73 KB

Nội dung

Instructor Inputs Session 7 ¤NIIT Instructor Inputs 7.3 This session includes Chapter 5 of the Student Guide. Slide 1 Slide 1 of 20Session 7 Ver. 1.0 Querying and Managing Data Using SQL Server 2005 In this session, you will learn to: Manipulate data by using Data Manipulation Language statements Manipulate the Extensible Markup Language data Objectives Begin the session by sharing the session objectives with the students. Slide 2 Slide 2 of 20Session 7 Ver. 1.0 Querying and Managing Data Using SQL Server 2005 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… Storing Data in a Table Session Overview 7.4 Instructor Inputs ¤NIIT In this topic, 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. For this, you can use the examples given in the Student Guide. Slide 3 Slide 3 of 20Session 7 Ver. 1.0 Querying and Managing Data Using SQL Server 2005 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… Storing Data in a Table (Contd.) Tell the students that while inserting rows, it is a good practice to mention the column list. Emphasize on the following guidelines to insert data:  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. To demonstrate the example to insert data in the Address table, you need to create the Address table in the database. For this, you can use the CreateAddressTable.sql given in the DataFiles_for_Faculty\Chapter 05\01_Instep Demo folder in the TIRM CD. ¤NIIT Instructor Inputs 7.5 Slide 4 Slide 4 of 20Session 7 Ver. 1.0 Querying and Managing Data Using SQL Server 2005 Just a minute Which statement allows you to insert data in a table? Answer: INSERT INTO Reiterate the concepts taught earlier by asking the given question. Slide 5 Slide 5 of 20Session 7 Ver. 1.0 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 Reiterate the concepts taught earlier by asking the given question. 7.6 Instructor Inputs ¤NIIT Slide 6 Slide 6 of 20Session 7 Ver. 1.0 Querying and Managing Data Using SQL Server 2005 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… Updating Data in a Table 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. ¤NIIT Instructor Inputs 7.7 Slide 7 Slide 7 of 20Session 7 Ver. 1.0 Querying and Managing Data Using SQL Server 2005 Just a minute Which statement allows you to modify data in a database? Answer: UPDATE Reiterate the concepts taught earlier by asking the given question. Slide 8 Slide 8 of 20Session 7 Ver. 1.0 Querying and Managing Data Using SQL Server 2005 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… Deleting Data from a Table 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. 7.8 Instructor Inputs ¤NIIT Slide 9 Slide 9 of 20Session 7 Ver. 1.0 Querying and Managing Data Using SQL Server 2005 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… Deleting Data from a Table (Contd.) 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. 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. ¤NIIT Instructor Inputs 7.9 Slide 10 Slide 10 of 20Session 7 Ver. 1.0 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 Reiterate the concepts taught earlier by asking the given question. Slide 11 Slide 11 of 20Session 7 Ver. 1.0 Querying and Managing Data Using SQL Server 2005 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. Demo: Manipulating Data in Tables At the end of this demo, the students will be able to modify the data present in a table. 7.10 Instructor Inputs ¤NIIT Slide 12 Slide 12 of 20Session 7 Ver. 1.0 Querying and Managing Data Using SQL Server 2005 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. Demo: Manipulating Data in Tables (Contd.) Slide 13 Slide 13 of 20Session 7 Ver. 1.0 Querying and Managing Data Using SQL Server 2005 Flash presentation: Introduction to XML Store XML data in a table: By using XML data type By transforming XML data into a rowset Storing XML Data in a Table [...]... Datafiles_for_faculty\Chapter 05\01_Instep Demo folder of the TIRM CD NIIT Instructor Inputs 7. 13 Slide 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 Session 7 Ver 1.0 Slide 17 of 20 Reiterate the concepts taught earlier by asking the given question... Storing XML Data in a Table (Contd.) Storing XML data in a rowset involves the following tasks: 1 2 3 4 Parsing the XML document Retrieving a rowset from the tree Storing the data from the rowset Clearing the memory Let’s see how… Ver 1.0 NIIT Session 7 Slide 14 of 20 Instructor Inputs 7. 11 Tell the students that there are two ways to store XML data in tables: Using OPENXML: This method is used when you... 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 7. 14 Instructor Inputs Session 7 Slide 18 of 20 NIIT Slide 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... form of wellformed XML fragments Is performed by using: FOR XML clause in the SELECT statement XQuery language Ver 1.0 Session 7 Slide 15 of 20 While teaching the students how to store and retrieve XML data, you need to demonstrate the examples given in the chapter 7. 12 Instructor Inputs NIIT Before showing the example, execute the CreateCustomerDetails.sql database script, present in the Datafiles_for_faculty\Chapter... 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 NIIT Session 7 Slide 20 of 20 Instructor Inputs 7. 15 FAQs 1 What is the difference between the DELETE and TRUNCATE statements? Ans: The DELETE statement is used to delete specific rows from a table, whereas the TRUNCATE statement... 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 Session 7 Ver 1.0 Slide 19 of 20 Summarize the session Slide 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... gets the format as specified in the SELECT statement Let’s see how… Ver 1.0 Session 7 Slide 16 of 20 These directives explain how the rowset data will be converted in the XML format Refer the Student Guide for detailed explanation of the examples The chapter also discusses how to extract data using XQuery According to the session plan, you will not demonstrate this topic in the class However, you can... previous versions of SQL Server? Ans: In the previous versions of SQL Server, the XML data was stored in textual format Where as, in SQL Server 2005, XML data can be stored in the XML format itself 7. 16 Instructor Inputs NIIT .. .Inputs for the Flash Presentation This presentation gives an overview to XML It explains the need and advantages of using XML In addition, it also explains the structure of an XML document Screen 1 A database server is accessed by heterogeneous clients These clients include desktop applications,... Collection: This method is used when you need to store the XML data in the XML format only In addition, you also need to validate that the XML data is verified against the given schema The plan for this session does not include how to store data using schema collection Also tell the students that for their additional knowledge the procedure to store data using schema is given in the book, which the students . Instructor Inputs Session 7 ¤NIIT Instructor Inputs 7. 3 This session includes Chapter 5 of the Student Guide. Slide 1 Slide 1 of 2 0Session 7 Ver. 1.0 Querying and. columns from two different tables with a single UPDATE statement. ¤NIIT Instructor Inputs 7. 7 Slide 7 Slide 7 of 2 0Session 7 Ver. 1.0 Querying and Managing Data Using SQL Server 2005 Just a minute. Datafiles_for_facultyChapter 051_Instep Demo folder of the TIRM CD. 7. 14 Instructor Inputs ¤NIIT Slide 17 Slide 17 of 2 0Session 7 Ver. 1.0 Querying and Managing Data Using SQL Server 2005 Just

Ngày đăng: 31/07/2014, 15:20

TỪ KHÓA LIÊN QUAN