Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 80 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
80
Dung lượng
1,99 MB
Nội dung
Collaborate Chapter 1 Querying,Managing,andAdministeringDatabasesUsingSQLServer2005 1.3 ¤NIIT In this section you will learn about: .NET Framework SQLServer2005 tools Grouping data by using the UNPIVOT operator Read the following topic in the Introduction to SQLServer2005 section of Chapter 1 of the book Querying and Managing Data UsingSQLServer 2005: The .NET Framework Read the following section of Chapter 1 of the book Querying and Managing Data UsingSQLServer 2005: Identifying the SQLServer2005 Tools The UNPIVOT operator allows database users to normalize the data that has earlier been pivoted. The UNPIVOT operator transforms the multiple column values of a record into multiple records with the same values in a single column. For example, a table that stores applicants’ records has one row for each applicant. The table stores the applicant’s name, qualification and grade. After applying the UNPIVOT operator on the table, the table contains a different row for each qualification that the applicant has completed. Knowledge Byte .NET Framework W orking with SQLServer2005 Tools Grouping Data by Using the UNPIVOT Operator ¤NIIT 1.4 Querying,Managing,andAdministeringDatabasesUsingSQLServer2005 The following table shows the structure of the Applicant table before using the UNPIVOT operator. Column Name Applicant Name Matriculation Higher Secondary Graduation Anderson A A B Samuel A B A Data Records Sandra B B B Applicant Table Before Using the UNPIVOT Operator The following table shows the structure of the Applicant table after using the UNPIVOT operator. Column Name Applicant Name Qualification Grade Anderson Matriculation A Anderson Higher Secondary A Anderson Graduation B Samuel Matriculation A Samuel Higher Secondary B Samuel Graduation A Sandra Matriculation B Sandra Higher Secondary B Data Records Sandra Graduation B Applicant Table After Using the UNPIVOT Operator Querying,Managing,andAdministeringDatabasesUsingSQLServer2005 1.5 ¤NIIT The syntax for using the UNPIVOT operator is: SELECT ApplicantName, newTable.Qualification, newTable.Grade FROM tblPivot UNPIVOT (Qualification FOR Grade IN (Matriculation, Higher Secondary, Graduation)) as tblUnPivot ¤NIIT 1.6 Querying,Managing,andAdministeringDatabasesUsingSQLServer2005 This section contains: Best practices Tips and tricks FAQs The following best practices can be considered while using the query statements in SQLServer 2005: When you write stored procedures, triggers, and user-defined functions, you need to decide whether to use traditional Transact-SQL or a programming language that is compatible with the .NET Framework, such as Visual Basic .NET or C#. Transact- SQL is best for situations in which the code primarily performs data access with little or no procedural logic. Programming languages that are compatible with the .NET Framework are best-suited for computationally-intensive functions and procedures that feature complex logic or for situations where you want to take advantage of the .NET Framework class library. To rotate the data of a table you can use the PIVOT and UNPIVOT operators, instead of using complex JOIN statements. SQLServer2005 provides three new data types for storing long columns: VARCHAR(MAX), NVARCHAR(MAX) and VARBINARY(MAX). These new data types are easier to use than the older large object data types, such as TEXT, NTEXT, and IMAGE. When building a new application that needs to store a column that possibly might exceed 8000 bytes, you should consider using these new large value data types. The total characters displayed in the Query Editor Results window are limited to 256 characters. If the result exceeds the limit of 256 characters, it gets truncated. In this case, you can use the Options tab in Management Studio to set the maximum column size under the Results section. The result sets that you return from your database should be kept as small as possible. This greatly improves the performance and makes the database much more scalable. From the Expert’s Desk Best Practices Querying,Managing,andAdministeringDatabasesUsingSQLServer2005 1.7 ¤NIIT The following tips and tricks will help you perform effective query by usingSQLServer 2005: When writing calculation expressions such as “expr1 * expr2”, ensure that the expression sweeping the largest area/volume is on the left side. For instance, write “Sales * ExchangeRate” instead of “ExchangeRate * Sales”, and “Sales * 1.15” instead of “1.15 * Sales”. Here Sales value will be larger than the exchange rate. Consider replacing simple “Measure1 + Measure2” calculations with computed columns in the SQL data source. Avoid using Select * in your query design. Instead, ensure that you use the proper column names in the query. Using the proper column names decreases network traffic, puts less load on the database, and therfore, improves performance. What are the two new components introduced with SQLServer 2005? The two new components introduced with SQL are: z SQLServer Management Studio z SQLServer Business Intelligence Development Studio Can we use the PIVOT and UNPIVOT operators in SQLServer 2000? No, SQLServer 2000 does not support the PIVOT and UNPIVOT operators. To achieve the same functionality as that of the PIVOT and UNPIVOT operators, you can use JOINS in SQLServer 2000. Which framework is supported by SQLServer 2005? SQLServer2005 supports Framework V2.0. Which application architecture does SQLServer2005 support? SQLServer2005 supports n-tier architecture. Which service of SQLServer2005 allows you to gather and integrate data from various disparate data sources available in an organization? Integration services of SQLServer2005 allow you to gather and integrate data from various disparate data sources available in an organization. Tips and Tricks FAQs ¤NIIT 1.8 Querying,Managing,andAdministeringDatabasesUsingSQLServer2005 1. Which of the following is not a component of the .NET Framework? a. Development tools and languages b. Base class library c. Service Broker d. Common Language Runtime 2. Which of the following component of the .NET Framework is used to create the interface for the Windows forms? a. Base class library b. Service Broker c. Development tools and languages d. Common Language Runtime 3. Which component of the .NET Framework provides an environment for the application to run? a. Development tools and languages b. Base class library c. Security Management d. Common Language Runtime 4. Which of the following is not a feature provided by the common language runtime? a. Service-oriented architecture b. Language interoperability c. Automatic memory management d. Platform independence 5. Which of the following is not a main component of the SQLServer Management Studio interface? a. Solution Explorer b. Query Editor c. Object Explorer d. SQLServer Client Agent Challenge Querying,Managing,andAdministeringDatabasesUsingSQLServer2005 1.9 ¤NIIT 1. What is the maximum length of NVARCHAR data type? a. 8000 characters b. 6000 characters c. 4000 characters d. 400 characters 2. Which of the following data type does not store integer value? a. tinyint b. int c. smallint d. decimal 3. Which operator is used to change the precedence of the arithmetic operators in SQL queries? a. \ b. [ ] c. ( ) d. { } 4. Which of the following query retrieves the record of the students who are studying in a class higher than class 10? a. SELECT * FROM Student WHERE NOT class<=10 b. SELECT * FROM Student WHERE class=10 c. SELECT * FROM Student WHERE class>=10 d. SELECT * FROM Student WHERE NOT class>=10 5. Which of the following query retrieves the names of the cities that start with letter M and whose fourth letter is B? a. SELECT City FROM City_List WHERE City LIKE ‘M_ B_%’ b. SELECT City FROM City_List WHERE City LIKE ‘M_ _ B[]’ c. SELECT City FROM City_List WHERE City LIKE ‘M_ _ B%’ d. SELECT City FROM City_List WHERE City LIKE ‘M% B%’ 6. Which SQLServer2005 service provides data mining solutions that are built on data integrated in the data warehouse? a. Analysis services b. Reporting services c. Database engine d. Integration services Home Assignment ¤NIIT 1.10 Querying,Managing,andAdministeringDatabasesUsingSQLServer2005 7. Which type of statement in SQLServer allows you to control the data access in the database? a. DML b. DCL c. DDL d. DQL 8. Which data type is used to store fixed length character data? a. text b. varchar(n) c. char(n) d. nchar 9. Which clause allows you to group data in a SELECT statement? a. WHERE b. HAVING c. ORDER BY d. COMPUTE BY 10. Which group operator is used to transform a set of columns into values? a. COMPUTE b. COMPUTE BY c. GROUP BY d. PIVOT [...]... Querying and Managing Data UsingSQLServer 2005: Storing XML Data in XML columns Using XQuery Read the following topic in the section Manipulating the XML Data of Chapter 5 of the book Querying and Managing Data UsingSQLServer 2005: Using XQuery NIIT Querying,Managing,andAdministeringDatabasesUsingSQLServer2005 3.3 From the Expert’s Desk This section contains: Best practices Tips and tricks... customize the result set in SQLServer2005Using Functions to Customize the Result Set Read the following section of Chapter 2 of the book Querying and Managing Data UsingSQLServer 2005: Using Functions to Customize the Result Set NIIT Querying,Managing,andAdministeringDatabasesUsingSQLServer2005 2.3 From the Expert’s Desk This section contains: Best practices Tips and tricks FAQs Best Practices... sp_prepareddocument @Doc OUTPUT, @XMLDoc d sp_xml_preparedocument @Doc OUTPUT NIIT Querying,Managing,andAdministeringDatabasesUsingSQLServer2005 3.9 10 Which mode of the FOR XML clause is used to return query results as nested XML elements? a RAW b PATH c AUTO d EXPLICIT 3.10 Querying,Managing,andAdministeringDatabasesUsingSQLServer2005 NIIT Chapter 4 Collaborate Knowledge Byte In this... topic in the section Creating and Managing Indexes of Chapter 6 of the book Querying and Managing Data UsingSQLServer 2005: Creating Partitioned Indexes System-Defined Procedures Read the following topic in the Appendix of the book Querying and Managing Data UsingSQLServer 2005: System-Defined Procedures NIIT Querying,Managing,andAdministeringDatabasesUsingSQLServer2005 4.3 From the Expert’s... refresh the definition of the view by using the sp_refreshview system stored procedure 4.4 Querying,Managing,andAdministeringDatabasesUsingSQLServer2005 NIIT Tips and Tricks The following tips and tricks will help you use views, batches, stored procedures, and functions in SQLServer 2005: Use SET_NOCOUNT_ON at the beginning of SQL batches, stored procedures, and triggers This will increase the... ALL d LIKE 2.8 Querying,Managing,andAdministeringDatabases Using SQLServer2005 NIIT Chapter 3 Collaborate Knowledge Byte In this section, you will learn about: Creating an XML document Storing XML data in XML columns Using XQuery Creating an Extensible Markup Language (XML) Document Read the following topic in the Appendix of the book Querying and Managing Data UsingSQLServer 2005: Extensible... effectively use DML commands and use indexes in SQLServer 2005: To change the date and time on the Windows server where SQLServer is installed, use the following script in Query Editor: USE master EXEC xp_cmdshell 'echo 06/16 /2005 | date' EXEC xp_cmdshell 'echo 15:01:40 | time' The first EXEC command changes the date in the SQLServer The second EXEC command changes the time in the SQLServer To check whether... default NIIT Querying,Managing,andAdministeringDatabasesUsingSQLServer2005 3.5 What is the maximum limit of creating partitions? The maximum limit of creating partitions is 1000 Does SQLServer 2000 have a support for partition tables? No, SQLServer 2000 does not support partition tables How is the indexed view updated when any row is inserted, updated or deleted from a table? The SQLServer maintains... as the default value for a column of char type 2.4 Querying,Managing,andAdministeringDatabasesUsingSQLServer2005 NIIT FAQs What is the difference between the DELETE and TRUNCATE commands? The DELETE command removes the rows from a table based on the condition provided with the WHERE clause The TRUNCATE command removes all the rows from a table and does not give an option to selectively delete... for the clustered index, SQLServer helps you sequentially read the data in a clustered index an extent (8 data pages, or 64K) at a time This makes it easy for the disk subsystem to read the data quickly from disk, especially if there is a lot of data to be retrieved 3.4 Querying,Managing,andAdministeringDatabasesUsingSQLServer2005 NIIT Tips and Tricks The following tips and tricks will help you . 1 Querying, Managing, and Administering Databases Using SQL Server 2005 1.3 ¤NIIT In this section you will learn about: .NET Framework SQL Server 2005 tools Grouping data by using. Framework W orking with SQL Server 2005 Tools Grouping Data by Using the UNPIVOT Operator ¤NIIT 1.4 Querying, Managing, and Administering Databases Using SQL Server 2005 The following table. FAQs ¤NIIT 2.6 Querying, Managing, and Administering Databases Using SQL Server 2005 1. Identify the output of the following command: Select left( SQL Server ,3) a. Ser b. SQL c. ver d.