Archive for April, 2009

194 Part I EXAM PREPARATION The SQL SELECT

Thursday, April 30th, 2009

194 Part I EXAM PREPARATION The SQL SELECT Statement Using the T-SQL SELECT statement is the most common way of accessing data. The majority of all data retrieval statements begins with these four fundamental parts of a SELECT operation: SELECT. Specifies the columns from the tables that need to be retrieved. FROM. Specifies where the table(s) and the columns are located. WHERE. Specifies a condition in order to filter data down. ORDER BY. Specifies how you want to order the data after it s been retrieved. The following code illustrates the use of the standard clauses within a SELECT query: EXAMPLE: SELECT * FROM Northwind.dbo.CUSTOMERS ORDER BY CompanyName (* retrieves all columns) SELECT statements can be made very complex with the use of options that can join many tables together and with functions that can calculate and summarize data at the same time. SELECT statements also can often be as simple as one line of code that retrieves the requested data. The complete SELECT syntax is very involved with many optional portions. The complete syntax reference can be found in SQL Server blogs Online (BOL) under SELECT, SELECT (described). Many of the options are used only under special circumstances. Take the following one-line code, for instance. Notice the simplicity required to code it and also note that at least the first two sub-statements are specified. SELECT * FROM Pubs.dbo.AUTHORS This statement retrieves all columns and rows from the authors table in the Pubs database. The SELECT statement s syntax is relatively simple as shown in the following: Select [all|distinct] columnlist From tablelist Where condition(s) OrderBy columnname type The descriptions for the arguments are shown in Table 4.1

For high quality java hosting services please check java web hosting website.

Chapter 4 QUERYING AND MODIFYING DATA 193 INTRODUCTION

Thursday, April 30th, 2009

Chapter 4 QUERYING AND MODIFYING DATA 193 INTRODUCTION After data is in the database, it is inevitable that the data will need to be accessed, changed, and reported on. To perform these basic operations, you need to be able to apply the programming constructs of Structured Query Language (SQL) specifically, Microsoft s implementation referred to as Transact-SQL (T-SQL). Understanding how to access and modify data is vital for any developer, beginner, or expert. This chapter discusses the not-so-tough topics of querying and modifying data, and then proceeds to the more advanced topics of data retrieval and modification. DATA RETRIEVAL Two utilities are built into SQL Server to allow for the interactive use of T-SQL. SQL Query Analyzer and the OSQL utility support using T-SQL interactively to view, process, and modify data. A third utility, the BCP utility, could be used to import or export large amounts of data. SQL Query Analyzer and OSQL are used to: Execute T-SQL statements. Save the resultsets in a file. Show the results of a query to the user. With SQL Query Analyzer, you can connect concurrently to numerous instances of SQL Server. However, the OSQL and BCP utilities enable you to work with only one instance at a time. Queries in SQL Server refer to a set of T-SQL statements that are issued to the database to retrieve data. The most common method of data retrieval is using the SELECT T-SQL statement. The SELECT statement is the basis for the majority of the activity performed in data retrieval. It is the first statement for a SQL developer to master, as its use is varied and can involve many options.

If you looking for unlimited one inclusive web hosting plan please check unlimited web hosting website.

OUTLINE STUDY STRATEGIES Data Retrieval The SQL SELECT

Wednesday, April 29th, 2009

OUTLINE STUDY STRATEGIES Data Retrieval The SQL SELECT Statement FROM Which Table? The WHERE Clause ORDER Data Filtering and Formatting Data Filtering Data Formatting the Data Data Summary Date Functions Using Mathematical Functions in T-SQL Character Functions System Functions Making Data Modifications Inserting Data into Tables Deleting Data Updating Data Apply Your Knowledge Exercises Review Questions Exam Questions Answers To Review Questions Answers To Exam Questions 193 . This chapter is one you need to fully understand. Try reading this chapter more than once 194 if needed. 199 . Be sure to follow the Step by Steps because 200 practical work in this chapter is exceptionally 202 vital. After reading through this chapter, practice creating queries using all the functions and methods mentioned in this chapter. 203 204 214 217 218 221 224 227 231 231 234 235 239 239 241 241 245 245

For reliable and cheap web hosting services please check tomcat web hosting website.

OBJECTIVES Retrieve data by using Transact-SQL. . This

Tuesday, April 28th, 2009

OBJECTIVES Retrieve data by using Transact-SQL. . This objective requires you to know how to access data in different ways, providing for different looks into the data with user-friendly views and other reporting methods from the data source. Filter data by using Transact-SQL. . You don t often want all the data from the tables. Usually queries want to limit the number of columns and rows displayed from the database. You need to limit and specifically apply conditions over the data that is transmitted to the user interface. Summarize data by using Transact-SQL. . A database system needs to generate other information beyond just the data. Arithmetic, statistical analysis, and other operations are needed in a full- service database implementation. Modify data by using Transact-SQL. . This objective requires you to also know how to modify existing data in a table using statements such as UPDATE. CHAPTER 4 Querying and Modifying Data

For high quality jboss hosting services please check jboss web hosting website.

190 Part I EXAM PREPARATION A PPLY YOUR

Tuesday, April 28th, 2009

190 Part I EXAM PREPARATION A PPLY YOUR K NO WLEDGE 11. A, E. The UNIQUE constraint on the Parts table UPC column is required first, so that the FOREIGN KEY constraint can be applied from the OrderDetails.UPC column referencing Parts.UPC. This achieves the referential integrity requirement. It also reduces I/O required during joins between Parts and OrderDetails, which make use of the FOREIGN KEY constraint defined. For more information, see Maintaining Referential Integrity. 12. A. To obtain the physical storage sequence of the data, you must use a clustered constraint or index. Although a Primary Key would also provide for the level of uniqueness, it is not the desired key for this table. For more information, see Unique Indexing in Chapter 10. 13. C. A single table could provide all the necessary information with no redundancy. The table could easily be represented using a self-join operation to provide the desired reporting. Join operations will be discussed in detail in the next chapter. 14. A. Using identities in this fashion enables records to be entered that have no overlap. One location would use entry values 1, 7, 13, 19; the next would have 2, 8, 14, 20; the third 3, 9, 15, 21, and so on. For more information, see Application of Integrity Options. 15. C. This is a many-to-many relationship scenario, which in SQL Server is implemented using three tables. The center table, often referred to as the connecting or joining table, is on the many side of both of the relationships to the other base table. For more information, see Maintaining Referential Integrity. Suggested Readings and Resources 1. Inside SQL Server 2000 Kalen Delaney (www.insidesqlserver.com) Not a beginner blog, but it fills in many of the gaps left out of the SQL Server blogs Online documentation. Explains fully how SQL Server stores and processes data internally. 2. SQL Server 2000 blogs Online Creating and Maintaining Databases (Look particularly at the sections on indexes, views, and triggers.) Transact-SQL Reference (Use this as a resource for the specific syntax requirements of each statement, as well as some code examples.) Optimizing Database Performance (Focus on Database and Application Design.) Troubleshooting: Server and Database Troubleshooting 3. MSDN Online Internet Reference (http://msdn.microsoft.com) Transact SQL Overview (/library/psdk/sql/ts_tsqlcon_6lyk.htm) Transact SQL Syntax Conventions (/library/psdk/sql/ts_syntaxc_9kvn.htm) Transact SQL Tips (/library/psdk/sql/ac_8_qd_14_2kc3.htm)

For high quality website hosting services please check tomcat web hosting website.

Chapter 3 PHYSICAL DATABASE DESIGN AND IMPLEMENTATION 189

Monday, April 27th, 2009

Chapter 3 PHYSICAL DATABASE DESIGN AND IMPLEMENTATION 189 APPLY YOUR KNOWLEDGE desired and would have to be complemented with the actions of a trigger. Disabling referential integrity is a poor solution to any problem, especially considering the medical nature of this application and the possible ramifications. For more information, see Trigger Utilization. 3. D. Because the IMAGE data will seldom be accessed, it makes sense to get the remainder of the data away from the images while moving the log away from the data. This will help to improve performance while providing optimum recover- ability in the event of a failure. For more information, see Using Filegroups. 4. D. Good controllers suitable for database use will have a battery backup. The battery should be regularly tested under controlled circumstances. Disabling caching if currently in place is likely to affect performance, as will enabling torn page detection. Torn page detection might help point out whether data is being corrupted because of failures. A maintenance plan is recommended, although it is not an entire solution in its own right. 5. A. Because a trigger is already in place, it can easily be altered to perform the additional data check. A rule cannot provide the required functionality because you cannot compare the data. The CHECK constraint may be a viable solution but you would have to alter the trigger to check for an error and provide for nested operations. The number of triggers firing should be kept to a minimum. To accommodate additional triggers, you would have to check the order in which they are being fired and again set properties of the server and database accordingly. For more information, see Trigger Utilization. 6. C. Because the majority of the reporting is going to be performed using the storage location, it would be the likely candidate. The clustered index represents the physical order of the data and would minimize sorting operations when deriving the output. For more information, see Index Organization. 7. C. Simple Recovery uses the least amount of log space for recording changes to the database. Full recovery uses the most space because it fully logs any bulk operations. Bulk recovery represents a mid-point between the two. Auto Close frees up resources at the earliest possible point during process execution, and Auto Shrink minimizes the space used in the file system by periodically reducing the files when there is too much unused space. For more information, see Use of Recovery Models. 8. B, C, D, E. All these options have activities that provide or alter data so that it does not have to be performed as an entry operation. In the case of NULL, data need not be provided, possibly because the column contains non-critical information. For more information, see Table Characteristics. 9. D. Use AUTOGROW to set the system so that the files will grow as needed for the addition of new data. You may want to perform a planned shrinkage of the database as part of the quarter-ending process and save on overhead by leaving the AUTOSHRINK option turned off. For more information, see Creating Database Files and Filegroups. 10. A. You need to add a constraint to prevent negative data entry. The best method of implementing this functionality is a constraint. A trigger has too much overhead and the RULE is not accurately implemented. A procedure could handle the process but is normally only used for processes requiring more complex logic. For more information, see Table Characteristics.

For reliable and cheap web hosting services please check tomcat web hosting website.

188 Part I EXAM PREPARATION A PPLY YOUR

Sunday, April 26th, 2009

188 Part I EXAM PREPARATION A PPLY YOUR K NO WLEDGE C. Create a new entry; create a one-to-many relationship from the employee to the new entry; and create a one-to-many relationship from the department entry to the new entry. D. Create a new entry; create a one-to-many relationship from the new entry to the employee entry; then create a one-to-many relationship from the entry to the department entry. Answers to Review Questions 1. Configuring a Cascading Delete Action causes the deletion of a record to propagate deletions throughout the underlying related table. This option should be configured with caution, because the deletion of underlying data might not be desired. You need to set two tables up in a parent-child relationship, using appropriate Primary and Foreign Keys. Cascading Update Action performs a similar operation when key values are changed, propagating the new values to underlying child tables. 2. First, put the log files onto a volume other than where the data is stored to ensure optimum recoverability. If possible, use a mirror on the OS volume to minimize downtime in a system failure. If the data volume becomes corrupt, a restore can be performed to get that data back. Having the log on a separate volume means that you can recover additional data because the log volume should be unaffected by the damage to the data. 3. Referential integrity is used to create a link between two related tables. A Foreign Key in one table references a Primary Key or unique index in the other table. Any entry to the table in which the Foreign Key resides must have a matching record in the table containing the Primary Key. Rules, constraints, triggers, and defaults all participate in maintaining data integrity. 4. Both filegroups must be backed up within the same backup set whenever the indexes are separated from the data. Care must be taken so that the indexes always maintain pointers to the corresponding data. 5. In SQL Server, there are several uses of the term schema. Information, Database, XML, and Warehouse all use schema to define the structure of elements, whether they be statistics, data dictionaries, data structures, or cube dimensions. Answers to Exam Questions 1. B. This is a perfect example of where partitioning a table into two smaller objects enables you to use two machines to help reduce the load on the overall application. Remember that failover clustering is the only form of clustering supported by SQL and therefore does not actually reduce the load; it only assists in obtaining an around-the-clock operation. Log shipping assists in offloading query load, but does little to reduce update load because it leaves the second server in a read-only state. Merge replication may enable updates to span many servers, but the associated overhead and data latency makes it a less than desirable alternative. For more information, see Partitioning to Achieve a Balance. 2. D. The INSTEAD OF trigger was designed specifically for this type of situation and also to handle complicated updates where columns are defined as Timestamp, Calculated, or Identity. Cascade operations are inappropriate because the updated key is not always stored. Indexed views by themselves do not allow for the type of alteration

If you looking for unlimited one inclusive web hosting plan please check web hosting plan website.

Chapter 3 PHYSICAL DATABASE DESIGN AND IMPLEMENTATION 187

Sunday, April 26th, 2009

Chapter 3 PHYSICAL DATABASE DESIGN AND IMPLEMENTATION 187 APPLY YOUR KNOWLEDGE 12. You are the database developer for a leasing company. Your database includes a table that is defined as follows: CREATE TABLE Lease (Id Int IDENTITY NOT NULL CONSTRAINT pk_lesse_id PRIMARY KEY .NONCLUSTERED, Lastname varchar(50) NOT NULL, FirstName varchar(50) NOT NULL, SSNo char(9) NOT NULL, Rating char(10) NULL, Limit money NULL) Each SSNo must be unique. You want the data to be physically stored in SSNo sequence. Which constraint should you add to the SSNo column on the Lease table? A. UNIQUE CLUSTERED constraint B. UNIQUE UNCLUSTERED constraint C. PRIMARY KEY CLUSTERED constraint D. PRIMARY KEY UNCLUSTERED constraint 13. You are building a database and you want to eliminate duplicate entry and minimize data storage wherever possible. You want to track the following information for employees and managers: First name, middle name, last name, employee identification number, address, date of hire, department, salary, and name of manager. Which table design should you use? A. Table1: EmpID, MgrID, Firstname, Middlename, Lastname, Address, Hiredate, Dept, Salary. Table2: MgrID, Firstname, Middlename, Lastname. B. Table1: EmpID, Firstname, Middlename, Lastname, Address, Hiredate, Dept, Salary. Table2: MgrID, Firstname, Middlename, Lastname. Table3: EmpID, MgrID. C. Table1: EmpID, MgrID, Firstname, Middlename, Lastname, Address, Hiredate, Dept, Salary. D. Table1: EmpID, Firstname, Middlename, Lastname, Address, Hiredate, Dept, Salary. Table2: EmpID, MgrID Table3: MgrID. 14. You are developing an application and need to create an inventory table on each of the databases located in New York, Detroit, Paris, London, Los Angeles, and Hong Kong. To accommodate a distributed environment, you must ensure that each row entered into the inventory table is unique across all locations. How can you create the inventory table? A. Supply Identity columns using a different sequential starting value for each location and use an increment of 6. B. Use the identity function. At first location, use IDENTITY(1,1), at second location use IDENTITY(100000,1), and so on. C. Use a Uniqueidentifier as the key at each location. D. Use TIMESTAMP column as the key at each location. 15. You are building a new database for a company with ten departments. Each department contains multiple employees. In addition, each employee might work for several departments. How should you logically model the relationship between the department entity and the employee entity? A. A mandatory one-to-many relationship between department and employee. B. An optional one-to-many relationship between department and employee.

For reliable and cheap web hosting services please check tomcat web hosting website.

186 Part I EXAM PREPARATION APPLY YOUR KNOWLEDGE

Saturday, April 25th, 2009

186 Part I EXAM PREPARATION APPLY YOUR KNOWLEDGE tant to be able to attain a point-in-time restoration process. You would like to minimize the maintenance needed to accommodate increases and decreases in file storage space. Which option would assist the most in accomplishing the task? A. SIMPLE RECOVERY B. AUTOSHRINK C. MAXSIZE D. AUTOGROW E. COLLATE 10. You are the administrator of a SQL Server 2000 computer. The server contains a database named Inventory. Users report that several storage locations in the UnitsStored field contain negative numbers. You examine the database s table structure. You correct all the negative numbers in the table. You must prevent the database from storing negative numbers. You also want to minimize use of server resources and physical I/O. Which statement should you execute? A. ALTER TABLE dbo.StorageLocations ADD .CONSTRAINT CK_StorageLocations_UnitsStored CHECK (UnitsStored >= 0) B. CREATE TRIGGER CK_UnitsStored On .StorageLocations FOR INSERT, UPDATE AS IF INSERTED.UnitsStored < 0 ROLLBACK TRAN C. CREATE RULE CK_UnitsStored As @Units >= 0 GO sp_bindrule CK_UnitsStored StorageLocations.UnitsStored GO D. CREATE PROC UpdateUnitsStored (@StorageLocationID int, @UnitsStored .bigint) AS IF @UnitsStored < 0 RAISERROR (50099, 17) ELSE UPDATE StorageLocations SET UnitsStored = @UnitsStored WHERE StorageLocationID = .@StorageLocationID 11. You are the administrator of a SQL Server 2000 computer. The server contains a database named Inventory. In this database, the Parts table has a Primary Key that is used to identify each part stored in the company s warehouse. Each part has a unique UPC code that your company s accounting department uses to identify it. You want to maintain the referential integrity between the Parts table and the OrderDetails table. You want to minimize the amount of physical I/O that is used within the database. Which two T-SQL statements should you execute? (Each correct answer represents part of the solution. Choose two.) A. CREATE UNIQUE INDEX IX_UPC On Parts(UPC) B. CREATE UNIQUE INDEX IX_UPC On .OrderDetails(UPC) C. CREATE TRIGGER UPCRI On OrderDetails FOR INSERT, UPDATE As If Not Exists (Select UPC From Parts Where Parts.UPC = inserted.UPC) BEGIN ROLLBACK TRAN END D. CREATE TRIGGER UPCRI On Parts FOR INSERT, UPDATE As If Not Exists (Select UPC From Parts Where OrderDetails.UPC = inserted.UPC) .BEGIN ROLLBACK TRAN END E. ALTER TABLE dbo.OrderDetails ADD .CONSTRAINT FK_OrderDetails_Parts FOREIGN KEY(UPC) REFERENCES dbo.Parts(UPC) F. ALTER TABLE dbo.Parts ADD CONSTRAINT FK_Parts_OrderDetails FOREIGN KEY (UPC) REFERENCES dbo.Parts(UPC)

If you looking for unlimited one inclusive web hosting plan please check unlimited web hosting website.

Chapter 3 PHYSICAL DATABASE DESIGN AND IMPLEMENTATION 185

Friday, April 24th, 2009

Chapter 3 PHYSICAL DATABASE DESIGN AND IMPLEMENTATION 185 APPLY YOUR KNOWLEDGE B. Create a check constraint with the No Check option enabled on the customer table, so that any inappropriate order is refused. C. Create a rule that doesn t permit an order that exceeds the limit and bind the rule to the Orders table. D. Create a new trigger on the Orders table that refuses an order that causes the balance to exceed the maximum. Apply the new trigger to only INSERT and UPDATE operations. 6. An existing sales catalog database structure exists on a system within your company. The company sells inventory from a single warehouse location that is across town from where the computer systems are located. The product table has been created with a non-clustered index based on the product ID, which is also the Primary Key. Non- clustered indexes exist on the product category column and also the storage location column. Most of the reporting done is ordered by product category. How would you change the existing index structure? A. Change the definition of the Primary Key so that it is a clustered index. B. Create a new clustered index based on the combination of storage location and product category. C. Change the definition of the product category so that it is a clustered index. D. Change the definition of the storage location so that it is a clustered index. 7. You are the sole IT person working in a small branch office for a non-profit organization that deals with natural resource conservation issues. A non-critical database is maintained on the database server. You have been given the task of configuring appropriate database properties that would allow for a minimum use of execution time and storage resources. Which of the following set of properties is most appropriate? A. Full Recovery, Auto Shrink, Torn Page Detection B. Bulk Recovery, Auto Shrink, Single User C. Simple Recovery, Auto Close, Auto Shrink D. Simple Recovery, Auto Shrink, Single User E. Bulk Recovery, Auto Close, Auto Shrink 8. You are designing an application that will provide data entry clerks the capability of updating the data in several tables. You would like to ease entry and provide common input so the clerks need not enter data into all fields or enter redundant values. What types of technologies could you use to minimize the amount of input needed? Select all that apply. A. Foreign Key B. Cascading Update C. Identity Column D. Default E. NULL F. Primary Key G. Unique Index 9. A database that you are working on is experiencing reduced performance. The database is used almost exclusively for reporting, with a large number of inserts occurring on a regular basis. Data is cycled out of the system four times a year as part of quarter-ending procedures. It is always impor

If you looking for unlimited one inclusive web hosting plan please check unlimited web hosting website.