1.0 Querying, Managing, and Administering Databases using SQL Server 2005 Collaborative Session 4 Collaborate Session 5 Objectives In this session, you will learn about: Web services Sec
Trang 1Instructor Inputs S e
Trang 3This session includes the following topics:
Best practices
Tips and Tricks
Slide 1
Installing Windows XP Professional Using Attended Installation
Slide 1 of 17
Ver 1.0
Querying, Managing, and Administering Databases using SQL Server 2005
Collaborative Session 4 Collaborate Session 5
Objectives
In this session, you will learn about:
Web services Securing HTTP endpoints Best practices that can be considered while using triggers and transactions in SQL Server 2005
Tips and tricks that will help you effectively use triggers and transaction statements in SQL Server 2005
FAQs related to triggers and managed code in SQL Server 2005
Trang 45.4 Instructor Inputs ¤NIIT
Slide 2 of 17
Ver 1.0
Collaborative Session 4 Collaborate Session 5
Knowledge Byte
Web service:
Exposes a number of methods to provide functionality that can
be used by one or more applications, regardless of the programming languages, operating systems, and hardware platforms used to develop them.
Uses Internet standards, such as HTTP and XML, to communicate with client applications
Is similar to a component that provides a specific functionality.
Can be created by using any programming language in the NET suite, such as Visual Basic NET, Visual C# NET, and Visual C++ NET
Displays data on the Internet to trusted suppliers, customers,
or business partners However, you need to ensure that only appropriate people gain access to a critical data Therefore, it
is important to secure the HTTP endpoint.
Slide 3
Installing Windows XP Professional Using Attended Installation
Slide 3 of 17
Ver 1.0
Querying, Managing, and Administering Databases using SQL Server 2005
Collaborative Session 4 Collaborate Session 5
Knowledge Byte (Contd.)
To secure endpoints, perform the following steps:
Create appropriate user accounts within the database.
Grant permissions for any stored procedure or user-defined functions that the user or roles need to access by using the Web service.
Grant permissions to allow users or roles to connect to the HTTP endpoints.
Trang 5Slide 4 of 17
Ver 1.0
Collaborative Session 4 Collaborate Session 5
Best Practices
Use sp_recompile system procedure on a trigger or a stored procedure to recompile so that the updated procedure and trigger can be used.
Disable all the triggers on a database if you do not want to use them for sometime
The following command allows you to disable all triggers:
EXEC sp_MSforeachtable @command1="ALTER TABLE?
DISABLE TRIGGER ALL"
Slide 5
Installing Windows XP Professional Using Attended Installation Querying, Managing, and Administering Databases using SQL Server 2005
Best Practices (Contd.)
If you have to write complex procedural code use the CLR managed code It is faster than T-SQL statements
If you have data access task that contain little or no procedural code, use T-SQL programming
This is because you can write and execute it directly from the Code Editor Result window.
Trang 65.6 Instructor Inputs ¤NIIT
Slide 6 of 17
Ver 1.0
Collaborative Session 4 Collaborate Session 5
Tips and Tricks
You can create a trigger to extract the information of the record that is being changed by using the inserted and deleted tables.
You can use the managed code to create a trigger, stored procedure, and user defined function
You can resolve deadlocks in transactions by using a TRY/CATCH block
Use exception handling with the transactions If any exception occurs in a transaction execution, rollback the transaction
Slide 7
Installing Windows XP Professional Using Attended Installation
Slide 7 of 17
Ver 1.0
Querying, Managing, and Administering Databases using SQL Server 2005
Collaborative Session 4 Collaborate Session 5
How can you perform an action when the schema of a table
is changed?
You can use DDL triggers to perform an action when the schema of a table is changed DDL triggers can only be created to fire AFTER the triggering event has occurred, as opposed to DML triggers that can fire AFTER the event or INSTEAD OF the event.
FAQs
Trang 7Slide 8 of 17
Ver 1.0
Collaborative Session 4 Collaborate Session 5
Which category of triggers is available with SQL Server 2000?
SQL Server 2000 supports DML triggers SQL Server 2005 has introduced another category of trigger named DDL trigger.
FAQs (Contd.)
Slide 9
Installing Windows XP Professional Using Attended Installation Querying, Managing, and Administering Databases using SQL Server 2005
How can you restrict an update on the column of a table?
To restrict a column update, use the following syntax:
CREATE TRIGGER <trigger name>
ON <db name>.<table name>
FOR UPDATE AS
IF UPDATE(<col name>) BEGIN
RAISERROR ('Cannot be updated',10,1) ROLLBACK TRANSACTION
END GO
FAQs (Contd.)
Trang 85.8 Instructor Inputs ¤NIIT
Slide 10 of 17
Ver 1.0
Collaborative Session 4 Collaborate Session 5
Which new feature has been added to SQL Server 2005, which is an enhancement to T-SQL?
The NET Common Language Runtime is an enhancement to T-SQL It gives much more flexibility to programming in SQL Server 2005 as compared to T-SQL.
FAQs (Contd.)
Slide 11
Installing Windows XP Professional Using Attended Installation
Slide 11 of 17
Ver 1.0
Querying, Managing, and Administering Databases using SQL Server 2005
Collaborative Session 4 Collaborate Session 5
In which different languages can you write managed code?
You can write managed code by using Visual Basic, Visual C#, and Visual C++.
FAQs (Contd.)
Trang 9Slide 12 of 17
Ver 1.0
Collaborative Session 4 Collaborate Session 5
Challenge
Which of the following is not a standard for Web service?
UDDI HTML WSDL SOAP
Answer:
HTML
Slide 13
Installing Windows XP Professional Using Attended Installation Querying, Managing, and Administering Databases using SQL Server 2005
Challenge (Contd.)
Which of the following requirements does an application need to meet to use a Web service?
A standard format for designing a Web service
A standard language for sending messages from the client application to the Web service
A common data representation format of the data exchanged
A mechanism to allow a Web service to locate a client
Answer:
A common data representation format of the data exchanged
Trang 105.10 Instructor Inputs ¤NIIT
Slide 14 of 17
Ver 1.0
Collaborative Session 4 Collaborate Session 5
Challenge (Contd.)
Which of the following Web service standard describes a Web service?
WSDL UDDI XML SOAP
Answer:
WSDL
Slide 15
Installing Windows XP Professional Using Attended Installation
Slide 15 of 17
Ver 1.0
Querying, Managing, and Administering Databases using SQL Server 2005
Collaborative Session 4 Collaborate Session 5
Challenge (Contd.)
Which of the following is a correct sequence of steps to secure HTTP endpoints?
1 Create appropriate user accounts within the database.
2 Grant permission for a stored procedure or user-defined functions that the user needs to access by using a Web service.
3 Grant permission to users to connect to HTTP endpoints.
1 Create appropriate user accounts within the database.
2 Grant permission to users to access HTTP endpoints.
3 Grant permission to users for a stored procedure or user-defined functions that the user needs to access by using a Web service.
1 Create appropriate user accounts within the database.
2 Grant permission for a database that the user needs to access by using a Web service.
3 Grant permission to users to connect to HTTP endpoints.
Trang 11Slide 16 of 17
Ver 1.0
Collaborative Session 4 Collaborate Session 5
Challenge (Contd.)
Which of the following is a correct sequence of steps to secure HTTP endpoints?
1 Grant permission for a stored procedure or user-defined functions that the user needs to access by using a Web service.
2 Grant permission to users to connect to HTTP endpoints.
3 Create appropriate user accounts within the database.
Answer:
1 Create appropriate user accounts within the database.
2 Grant permission for a stored procedure or user-defined functions that the user needs to access by using
a Web service.
3 Grant permission to users to connect to HTTP endpoints.
Slide 17
Installing Windows XP Professional Using Attended Installation Querying, Managing, and Administering Databases using SQL Server 2005
Challenge (Contd.)
Which of the following information is not present in a WSDL document?
The Web service available for a given Web site.
The URL at which a Web service can be attached The format used to access the Web service The type of language that is used to create a Web service
Answer:
The type of language that is used to create a Web service
Trang 125.12 Instructor Inputs ¤NIIT
2 c A common data representation format of the data exchanged
4 a i Create appropriate user accounts within the database
ii Grant permission for a stored procedure or user-defined functions that the user needs to access by using a Web service
iii Grant permission to users to connect to HTTP endpoints
5 d The type of language that is used to create a Web service
Trang 131 Which of the following is true about DML triggers?
a They can be nested up to 35 levels
b They can return values
c They can be directly invoked
d They can prevent incorrect and unauthorized changes in data
2 Harry has updated a record in a table that has an update trigger Which magic
table/tables are used when a record is updated?
a Inserted table
b Updated table
c Deleted table
d Both inserted and deleted tables
3 Which of the following is not a DML trigger?
a Insert trigger
b Database trigger
c Delete trigger
d Update trigger
4 Which trigger can be used on a view?
a After trigger
b Instead of trigger
c Insert trigger
d Delete trigger
5 Which property of ACID ensures that either all or none of the data modifications are
performed?
a Atomicity
b Consistency
c Isolation
d Durability
Trang 145.14 Instructor Inputs ¤NIIT
c Intent locks
d Exclusive locks
8 Which isolation level specifies that a transaction can read the data modified by the current transaction even before the modifications are committed?
9 Which object is not created by using managed code?
a Stored procedure
c Trigger
10 Which authentication method uses MD5 hashing algorithm in the CREATE
ENDPOINT statement?
Solutions
1 They can prevent incorrect and unauthorized changes in data
2 Both inserted and deleted tables
3 Database trigger
4 Instead of trigger
5 Atomicity
6 Lost updates
7 Shared locks
10 DIGEST
Trang 15At times, while performing data manipulation on a database object, you might also need
to perform another manipulation on another object A trigger is a block of code that
constitutes a set of T-SQL statements activated in response to certain actions such as
insert or delete Triggers are used to ensure data integrity before or after performing data
manipulations
Discuss the different types of triggers that can be created by using SQL Server 2005
Instructor Inputs
You can conduct the discussion as follows:
Move the discussion toward the different types of triggers
Encourage the students to discuss the new category of triggers called DDL triggers
Solution
The SQL Server supports the following types of triggers:
Data Modification Language (DML) triggers
Data Definition Language (DDL) triggers
DML Triggers
A DML trigger is fired when data in the underlying table is affected by DML statements,
such as INSERT, UPDATE, or DELETE Depending on the operation that is performed,
the DML triggers can be further categorized as:
table
table
Trang 165.16 Instructor Inputs ¤NIIT