Archive for the 'sql' Category

OBJECTIVES Create and alter database objects. Objects include

Friday, November 20th, 2009

OBJECTIVES Create and alter database objects. Objects include triggers, and how to specify schema binding and encryption settings. . This objective in general requires you to know how to create triggers using the CREATE TRIGGER statement. When creating triggers, you also need to know how to set properties such as definition encryption. Manage data manipulation by using triggers including validate data. . This objective deals with controlling what goes in and what gets deleted in your table. You need to know how to create UPDATE, DELETE, and INSERT triggers and when to use them. Control data access by using triggers. . This objective is linked to the previous objective on managing data manipulation. This objective looks specifically at how triggers can be used to restrict which users are able to modify the data protected by a trigger. Enforce procedural business logic by using triggers. Specify trigger actions. Filter data by using triggers. . This objective looks at creating the actual contents of the trigger. This includes writing procedural code to fire when an UPDATE, DELETE, or INSERT statement is executed. Take a look at Chapter 6, Programming SQL Server 2000, to see how to create professional triggers. Troubleshoot and optimize programming objects. Objects include triggers. . This objective deals with altering and viewing triggers to make them more efficient. This chapter includes lots of tips to help you create efficient, working triggers. CHAPTER 8 Triggers

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

Chapter 7 WORKING WITH VIEWS 443 A PPLY

Thursday, November 19th, 2009

Chapter 7 WORKING WITH VIEWS 443 A PPLY YOUR K NO WLEDGE cannot be based on temporary tables. 7. When data is being modified, deleted, and updated through a view, the data definition in the view does not change; the data modification is aimed at the underlying referenced tables associated with the view. Answers to Exam Questions 1. B. A view does not contain data as a table does. It is often accessed with methods that are similar to those you use with a table, but the view is a definition or description of data that should be retrieved from a table or tables. For more information about view basics, see the section Understanding Views. 2. B. Partitioned views, and specifically distributed partitioned views, may improve the data access for Tom s database. Because a large number of rows could be separated by sales division per server (with one server maintaining information for two divisions), his database tables may be ideal candidates for distributed partitioned views. For more information about partitioned views, see the section Creating Partitioned Views. 3. A, B, D. The main benefits of views are that they disallow unneeded data, improve security enforcement, ease data exporting and generally make querying easier. For more information about the benefits for views, see the section View Benefits. 4. A, B. Both the Query Analyzer and the SQL Server Enterprise Manager can create views. For more information about creating views, see the section Creating Views. 5. B. A total of 1024 columns can be referenced in Suggested Readings and Resources a view definition. For more information about what a view is and some of its restrictions, see the section Understanding Views. 6. C. A distributed partitioned view collects data from two or more instances of SQL Server, hence the name distributed. Essentially, distributed partitioned views are used when you want to spread processing out over a group of servers, but want the data to be treated as a single unit. For more information about partitioned views, see the section Alter Database Objects to Support Partitioned Views. 7. C. The WITH CHECK OPTION forces all data modification statements executed against the view to adhere to the criteria set within the view definition. When a row is modified through a view, the WITH CHECK OPTION guarantees that the data remains visible through the view after the modification has been committed. For more information about restrictions on data modifications, see the section Updating Rows Through Views. 8. A. Horizontally filtering the table will work

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

442 Part I EXAM PREPARATION A PPLY YOUR

Wednesday, November 18th, 2009

442 Part I EXAM PREPARATION A PPLY YOUR K NO WLEDGE SELECT Jane.JaneView1.id, name, address, .description FROM Jane.JaneView1 INNER JOIN Jane.JaneView2 ON Jane.JaneView1.id = Jane.JaneView2.id Exhibit 3: Assign Permissions REVOKE all ON dbo.DBOTable1 TO public REVOKE all ON Jane.JaneTable1 TO public REVOKE all ON Bob.BobTable1 TO public GRANT SELECT ON Bob.BobView1 TO Jane, Mary GRANT SELECT ON Jane.JaneView1 TO Mary, Bob, .dbo GRANT SELECT ON dbo.DBOTable1 TO Jane GRANT SELECT ON Bob.BobTable1 TO Mary, Jane GRANT SELECT ON Jane.JaneTable1 TO Bob, dbo GRANT SELECT ON Jane.JaneView2 TO Mary A. When you create a view using WITH ENCRYPTION, you must use GRANT WITH DECRYPTION. B. One GRANT is missing for Mary. C. Two GRANTs are missing for Mary. D. There is nothing wrong with the code in the exhibits; the problem is likely with Mary s network connection. 13. Mary has created a view that is going to be used to create an employee phone list. She would like to sort the new view by the employees last names. She has tried to create the view using the ORDER BY clause, but it always fails. What can Mary do to create her view? A. Order the base table using a clustered index, then the required data will already be in the correct order. B. Use the TOP clause rather than the ORDER BY clause. C. Use the TOP clause in addition to the ORDER BY clause. D. This clause cannot be used. Answers to Review Questions 1. A view refers to data that is found in a table. The view does not actually contain any data. Although it takes up some space in the sysobjects and syscomments tables, in relative terms, the storage requirements are very small. 2. The CHECK constraint is used to identify which portion of the data can be found in which table. This published division speeds up searches for data through the view. 3. If you base a view on an existing view, you can further restrict, filter, or merge data that is currently defined through the existing view or views. 4. Generally, you would want to use a partitioned view when you want to gather information from many tables and make them appear as a single table. You may need to do this if you have split your data across several servers. This is done in some circumstances to improve data access performance. 5. You should implement a view in your database when you would like to disallow redundant data, enforce security, or export data easily. 6. Defaults, triggers and rules are not allowed to be associated with a view. INSTEAD OF triggers may be defined on a view. Even though a view is defined by a SELECT statement, it is not allowed to use the COMPUTE BY or SELECT INTO clauses. The ORDER BY clause may only be used in conjunction with the TOP clause. Finally, views

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

Chapter 7 WORKING WITH VIEWS 441 APPLY YOUR

Wednesday, November 18th, 2009

Chapter 7 WORKING WITH VIEWS 441 APPLY YOUR KNOWLEDGE D. Create it with the HIDDEN DEFINITION option. 10. You work with several developers who regularly CREATE, DROP, and ALTER views within your database. These actions have been causing many views to malfunction when dependent objects are altered. What option can you use to prevent some of your problems? A. CREATE INDEXED VIEW B. The WITH SCHEMABINDING option C. The WITH ENCRYPTION option D. The WITH CHECK option 11. Jeffery has just created a view to enforce data security on the Sales table. You are an assistant developer and are receiving complaints relating to the view Jeffery created some time ago. You assume that he made mistakes when creating the view and so in an attempt to do some cleanup, you try to access the view definition. When trying to access the definition of the view, you find that you are not able to. What is the most common reason to not be able to access a view definition? A. Jeffery specified the Encrypt On View option when he created the view. B. Jeffery specified SECURE DEFINITION when he created the view. C. Jeffery did not repair the view since the first time it was created three months ago. D. Jeffery used WITH ENCYPTION when he created the view. 12. You are troubleshooting an access problem with a view. Mary is having problems using Bob s new view, Bob.BobView1. Examine the following exhibits to figure out what is causing Mary s access problem. Exhibit 1 contains the tables that are in the database, Exhibit 2 contains the definitions of the views that are in the database, and Exhibit 3 are the permissions that were assigned to each object. After examining the exhibits, choose the best answer to explain Mary s access problem. Exhibit 1: Create Tables CREATE TABLE dbo.DBOTable1 ( id int, name varchar(20) ) CREATE TABLE bob.BobTable1 ( id int, description varchar(20) ) CREATE TABLE jane.JaneTable1 ( id int, address varchar(20) ) GO INSERT INTO dbo.DBOTable1 VALUES (1, Buddy ) INSERT INTO Jane.JaneTable1 VALUES (1, 123 .Some Street ) INSERT INTO Bob.BobTable1 VALUES (1, What .was his name? ) Exhibit 2: Create Views CREATE VIEW Jane.JaneView1 AS SELECT dbo.DBOTable1.id, name, address FROM dbo.DBOTable1 INNER JOIN Jane.JaneTable1 ON dbo.DBOTable1.id = Jane.JaneTable1.id GO CREATE VIEW Jane.JaneView2 WITH ENCRYPTION AS SELECT id, description FROM Bob.BobTable1 GO CREATE VIEW Bob.BobView1 AS

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

440 Part I EXAM PREPARATION APPLY YOUR KNOWLEDGE

Tuesday, November 17th, 2009

440 Part I EXAM PREPARATION APPLY YOUR KNOWLEDGE maximum number of columns that can be joined by the view John is creating? A. 250 B. 1024 C. It depends on the number of tables being referenced D. An unlimited amount 6. Jauna works for a trading company and has a massive amount of data held in databases that are found on multiple servers. This was done because they thought that putting the tables on multiple servers would ensure more efficient data access. Which of the following would you use to gather all this data into a single unit? A. Indexed view B. Replication view C. Distributed partitioned view D. Extended partitioned view 7. Your company keeps track of all sales on a monthly basis. The company requires that the sales manager enter all sales that are greater than $20,000 into a database. They do not want the sales manager to be able to enter values that are less than $20,000 in the database. You are in charge of creating a view for the Sales table that includes the following columns: amount, date, and sales_person. You would like this view to enable the sales manager to enter the valid sales figures. Which of the following describes the view needed? A. CREATE VIEW ApprovedSales AS SELECT date, Sales_Person, Amount FROM Sales WHERE Amount<=20000 B. CREATE VIEW ApprovedSales AS SELECT Number, SalesPerson, Amount FROM Sales HAVING Amount<=20000 C. CREATE VIEW ApprovedSales AS SELECT date, SalesPerson, Amount FROM Sales WHERE Amount<=20000 WITH CHECK OPTION D. CREATE VIEW ApprovedSales AS SELECT Number, SalesPerson, Amount FROM Sales HAVING Amount<=20000 WITH CHECK OPTION 8. Chris works as a SQL Server database developer in the technical department of a nationwide blogstore. Chris needs to create a view by filtering data for the 50 customers having greatest payments due from the Customers table. Which strategy would be the best for him to use? A. Retrieve slices of the Customers table horizontally B. Retrieve slices of the Customers table vertically C. Both A and B D. Use the filtered view, new to SQL Server 2000 9. You are working on your new view called SummaryData, which uses complex aggregates and joins for a company database. The view SummaryData you have just created took you a good amount of time and effort. You don t want other users to see how you created your view. What is the best and easiest way to implement this type of security? A. Create it with the WITH ENCRYPTION option. B. Create it with the WITH CHECK option. C. Create it in Enterprise Manager and select Hidden Definition

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

Chapter 7 WORKING WITH VIEWS 439 APPLY YOUR

Monday, November 16th, 2009

Chapter 7 WORKING WITH VIEWS 439 APPLY YOUR KNOWLEDGE based on a view, rather than on a table? 4. When would you want to use a partitioned view? 5. Generally speaking, when would you want to implement a view into your database? 6. Which objects are not allowed to be associated with a view? 7. When modifying data through a view, what are you actually modifying? Exam Questions 1. Which of the following statements best describes a view? A. A table stored on physical memory whose contents are derived from a query B. A definition of what data should be extracted from a table or tables C. A normal table except that it can be partitioned D. The way a table is shown is SQL Server 2. Tom is interested in examining ways to improve his data access performance through view implementations. He is currently managing a database that is replicated between five servers (for load balancing) and contains customer information for six sales divisions. The Customer table currently contains a consolidated list of 100,000 customer records. What could Tom try to implement to improve server performance? A. Aggregated views B. Partitioned views C. Complex views D. Full outer views 3. Which of the following is a benefit provided by a view? Choose all that apply. A. Minimize unneeded data. B. Security is enforced using views. C. Data is easily transformable. D. Data can be easily exported using tools, such as BCP. 4. Henry is the system administrator of the databases at his company. Users who access the database often query the Sales table, which has more than 50,000 rows and 15 columns. Most of the columns retrieved by users are unnecessarily retrieved. Henry needs to disallow the retrieval of the unnecessary columns and allow users to retrieve only the data that is needed. He decides to use a view. Which of the following tools can Henry use to create views? Choose all that apply. A. Query Analyzer B. SQL Server Enterprise Manager C. View Edit Wizard (VEW) D. None of the above 5. John works in a major telecom company. Each table in his central database has numerous columns and he wants to create a view by joining data from four tables. He does this, so that he can enable users to retrieve data efficiently from a view rather than retrieving the different columns manually by using JOIN statements. What is the

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

438 Part I EXAM PREPARATION APPLY YOUR KNO

Monday, November 16th, 2009

438 Part I EXAM PREPARATION APPLY YOUR KNO WLEDGE PRIMARY KEY CHECK (Identification BETWEEN 1 and 20), Name varchar(20) ) CREATE TABLE member2 ( Identification INT PRIMARY KEY CHECK (Identification BETWEEN 21 and 40), Name varchar(20) ) 3. Now INSERT some example data into the member tables you created in Step 1. To do this, execute the following queries: INSERT member1 (Identification, Name) VALUES ( 7 , Abraham ) INSERT member1 (Identification, Name) VALUES ( 18 , Jauna ) INSERT member2 (Identification, Name) VALUES ( 23 , John ) INSERT member2 (Identification, Name) VALUES ( 36 , Dennis ) 4. To create a view that combines these two member tables, execute the following: CREATE VIEW AllProducts AS SELECT * FROM member1 UNION ALL SELECT * FROM member2 5. Test your new view by running a SELECT against it. You should have a complete listing of all four records. Exercise 7.4 Accessing a View This exercise shows you how to access a view by displaying its definition and dependencies. Being able to research a view s definition and dependencies is useful when trying to find out why a view may not be working. Estimated Time: 10 minutes. 1. Open the SQL Server Query Analyzer by selecting it from the Start menu. Log in and select the Pubs database. 2. Create a new view by executing the following query: CREATE VIEW BusinessTitleView AS SELECT * FROM titles WHERE type = business 3. To access the definition of this view, execute the following: EXEC sp_helptext TitleView 4. To display any view dependencies, use the following query: sp_depends TitleView Review Questions 1. Describe in relative terms how much data a view is capable of containing and the storage requirements that may be necessary for a view. 2. How does the CHECK constraint help in the implementation of partitioned views? 3. What is the advantage of creating a view that is

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

Chapter 7 WORKING WITH VIEWS 437 APPLY YOUR

Sunday, November 15th, 2009

Chapter 7 WORKING WITH VIEWS 437 APPLY YOUR KNOWLEDGE query: CREATE VIEW SelectedColumns AS SELECT Au_ID, State, au_FName FROM Authors 3. Step 2 creates a view that includes only the State and Au_fname columns. To create a view that includes only rows where the first name has the letter J as the first letter, enter the following code: CREATE VIEW SelectedRows AS SELECT * FROM Authors WHERE au_fname LIKE J% 4. Test your view by running a SELECT against the view. Your SELECT statement should return all columns and rows so that you can see how much data is now available through the view. If you have not already done so, you should also SELECT the entire Authors table, in order to see how much data is in the base table. Exercise 7.2 Renaming and Dropping Views This example demonstrates renaming and dropping views using sp_rename and DROP VIEW. Any job that is done can either be done better or becomes obsolete. This exercise shows you how to change an established view s name, as well as remove an obsolete view. Estimated Time: 10 minutes. 1. Open the SQL Server Query Analyzer by selecting it from the Start menu. Connect to your server, and change to the Pubs database. 2. Examine the contents of the Titles table by selecting the entire contents. 3. You first have to create a view. To do this, enter the following code: CREATE VIEW ExampleView AS SELECT * FROM titles WHERE type = business 4. Test your new view by selecting against it. 5. To change the previously created view s name to TestView, enter the following code: sp_rename ExampleView , TestView , OBJECT 6. Examine what views exist in the Pubs database using the following statement: SELECT name FROM sysobjects WHERE type= V 7. To delete TestView (formerly ExampleView), enter the following query: DROP VIEW TestView 8. Re-examine the views that exist in the Pubs database using the same command that you used in Step 6. Exercise 7.3 Creating a Partitioned View This exercise demonstrates creating a partitioned view from member tables. You start by creating two base tables, and then you join them through the creation of a view. Estimated Time: 15 minutes. 1. Open the SQL Server Query Analyzer by selecting it from the Start menu. Connect to your server, and change to the Pubs database. 2. To begin, you will need to create two tables that act as members the tables that will be joined together. To do this, follow this code: CREATE TABLE member1 ( Identification INT

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

436 Part I EXAM PREPARATION APPLY YOUR KNO

Saturday, November 14th, 2009

436 Part I EXAM PREPARATION APPLY YOUR KNO WLEDGE SELECT, INSERT, UPDATE, and DELETE statements. The one major difference between views and tables was that views refer to tables, and do not actually contain their own data. A view could be related to a television set; it doesn t actually store movies but makes it possible for you to view them remotely. You saw that the CREATE VIEW statement defines the view, and saw that it is based on a SELECT statement, with some restrictions. The basic function of the statement is to define the range of data (columns and rows) that should be displayed from the table or tables used in the view. You also saw that many advanced features of the SELECT statement, such as joins and aggregates, carry over to views. Data modification with views introduced several restrictions that prevent many types of modifications (INSERT, UPDATE, and DELETE) from happening. You were introduced to the WITH CHECK OPTION, which further restricts what you can do. These restrictions serve two purposes: they enable you to validate the data you enter and to make restrictions to prevent unwanted data modifications. The next topic was ownership chains. You learned that if the same person owns a series of objects, such as views and the base tables, then she has to grant permissions to only the upper-layer objects or views. This is designed to make administration easier. You also learned what happens if you don t own all the objects, and what is required to grant access to the data. Object ownership should be limited to a single user: dbo. Data access performance was dealt with when you examined what partitioned views are. You learned that partitioned views can be local to one server or distributed across many servers. Two main items you had to remember about partitioned views were the use of CHECK constraints (to define what data is found in what table) and the view (which is created using the UNION ALL operator). KEY TERMS ALTER VIEW distributed partitioned view DROP VIEW local partitioned view partitioned view CREATE VIEW WITH ENCRYPTION WITH SCHEMABINDING Exercises Exercise 7.1 Creating a Filtered View This exercise demonstrates how to create two different views. These views implement vertical and horizontal filters. Many of the views that you will implement on databases will utilize some type of filtering. Estimated Time: 10 minutes. 1. Open the Query Analyzer from the Start menu. 2. To create a new view using vertical filtering, select the Pubs database and enter the following

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

436 Part I EXAM PREPARATION APPLY YOUR KNO

Saturday, November 14th, 2009

436 Part I EXAM PREPARATION APPLY YOUR KNO WLEDGE SELECT, INSERT, UPDATE, and DELETE statements. The one major difference between views and tables was that views refer to tables, and do not actually contain their own data. A view could be related to a television set; it doesn t actually store movies but makes it possible for you to view them remotely. You saw that the CREATE VIEW statement defines the view, and saw that it is based on a SELECT statement, with some restrictions. The basic function of the statement is to define the range of data (columns and rows) that should be displayed from the table or tables used in the view. You also saw that many advanced features of the SELECT statement, such as joins and aggregates, carry over to views. Data modification with views introduced several restrictions that prevent many types of modifications (INSERT, UPDATE, and DELETE) from happening. You were introduced to the WITH CHECK OPTION, which further restricts what you can do. These restrictions serve two purposes: they enable you to validate the data you enter and to make restrictions to prevent unwanted data modifications. The next topic was ownership chains. You learned that if the same person owns a series of objects, such as views and the base tables, then she has to grant permissions to only the upper-layer objects or views. This is designed to make administration easier. You also learned what happens if you don t own all the objects, and what is required to grant access to the data. Object ownership should be limited to a single user: dbo. Data access performance was dealt with when you examined what partitioned views are. You learned that partitioned views can be local to one server or distributed across many servers. Two main items you had to remember about partitioned views were the use of CHECK constraints (to define what data is found in what table) and the view (which is created using the UNION ALL operator). KEY TERMS ALTER VIEW distributed partitioned view DROP VIEW local partitioned view partitioned view CREATE VIEW WITH ENCRYPTION WITH SCHEMABINDING Exercises Exercise 7.1 Creating a Filtered View This exercise demonstrates how to create two different views. These views implement vertical and horizontal filters. Many of the views that you will implement on databases will utilize some type of filtering. Estimated Time: 10 minutes. 1. Open the Query Analyzer from the Start menu. 2. To create a new view using vertical filtering, select the Pubs database and enter the following

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