Bài giảng Cơ sở dữ liệu nâng cao Chapter 4 Transferring data and using service broker

45 202 0
  • Loading ...
1/45 trang

Thông tin tài liệu

Ngày đăng: 15/05/2017, 13:49

Bài giảng Cơ sở dữ liệu nâng cao Chapter 4 Transferring data and using service broker. Nội dung chính trong chương này gồm có Introduction, performing a bulk load, performing a bulk insert task, importing bulk XML data, overview of SQL server integration services, using the importexport wizard, service broker. CHAPTER Transferring Data and using Service Broker Agenda • Introduction • Performing a Bulk Load • Performing a Bulk Insert task • Importing Bulk XML data • Overview of SQL Server Integration Services • Using the Import/Export Wizard • Service Broker Introduction • A common task when working with a database is importing data from other sources • One of the most frequently used methods of transferring data • There are different methods you can use to efficiently import files into SQL Server • bulk copy program (bcp) • the BULK INSERT Transact-SQL command • the OPENROWSET Transact-SQL function • the SQL Server Integration Services (SSIS) Import/Export Wizard Performing bcp utility • Because bcp is a program, you not execute it from within a query window or batch but rather from the command line • It is an external program, which means it runs outside of the SQL Server process • bcp to bulk copy data either into or out of SQL Server Performing bcp utility • Two limitations of bcp: • bcp has limited data-transformation capabilities If the data that you are loading needs to go through complex transforms or validations, bcp is not the correct tool to use • bcp has limited error handling capabilities bcp might know that an error occurred while loading a given row, but it has limited reaction options Performing bcp utility bcp {dbtable | query} {in | out | queryout | format} datafile [option] Option Description -S Instance name -T -T Indicates that you wish BCP to connect using a trusted connection -U login name when not using –T -P the password associated with the –U login name -c Use a character data file type -w Use a Unicode data file type -t Field terminator -r Row terminator Performing bcp utility • bcp Command-Line Syntax bcp {dbtable | query} {in | out | queryout | format} datafile [option, n] Example about the simplest command bcp FileImportDB Exam out "c:\FileImportPractice\ExamImportFile.txt" -T –w bcp FileImportDB Exam in "c:\FileImportPractice\ExamImportFile.txt" -T -w BULK INSERT statement • Closely mimics the BCP command line utility • Two of the biggest differences between bcp and BULK INSERT BULK INSERT can only import data bcp can either import or export data Run inside the SQL Server Executed from the command process space and is executed line and runs outside of the from a query window or query SQL Server process space, batch BULK INSERT statement BULK INSERT {dbtable} FROM {datafile} [WITH (option)] BULK INSERT statement • Example: BULK INSERT FileImportDB Exam FROM 'c:\FileImportPractice\ExamImportFile.txt' Transforming Data with SSIS Understanding the Development Environment Understanding the Development Environment • Following steps to create SSIS solution • Creating the Connection • Creating the Data Flow Task • Defining the Destination Understanding the Development Environment • Following steps to create SSIS solution • Creating the Connection • Creating the Data Flow Task • Defining the Destination Overview of Service BrokerService Broker is a framework and extension to T-SQL, and can create and use the components for writing queue & building reliable and scalable message-based applications • Service Broker can take care of all the communication and messaging, enabling the developer to focus on the core problem domain • Service Broker is not enabled by default so the first specific step to working with Service Broker is to turn it on using the alter database command: ALTER DATABASE AdventureWorks SET ENABLE_BROKER; Service Broker Architecture • The core of Service Broker architecture is the concept of a dialog, which ordered exchange of messages between two endpoints • An endpoint is the sender or receiver of a message Service Broker Architecture Service Broker Architecture • Message type: is a definition of the format of a message • The message type is an object in a database • Messages are the information exchanged between applications that use Service Broker • The message type object defines the name of the message and the type of data it contains CREATE MESSAGE TYPE message_type_name [ AUTHORIZATION owner_name ] [ VALIDATION = { NONE| EMPTY| WELL_FORMED_XML | VALID_XML WITH SCHEMA COLLECTION schema_collection_name} ] Service Broker Architecture • Message type: • message_type_name: The name of the message type is just a SQL Server identifie • AUTHORIZATION owner_name: defines the owner of the message type • VALIDATION: specifies how Service Broker validates the message body for messages of this type When this clause is not specified, validation defaults to NONE • Example: CREATE MESSAGE TYPE [//www.wrox.com/order/orderentry] VALIDATE = WELL_FORMED_XML Service Broker Architecture • Contracts: define which message type can be used in a conversation • When a contract is created, at least one message type needs to be marked as SENT BY INITIATOR or SENT BY ANY Obviously, a message type must exist before you create the contract • In addition, the message type and direction cannot be changed once the contract is defined  cannot alter the contract once you create it • If you have to change the message type, then you must first drop the contract if you have defined one for that message type Service Broker Architecture • Queue: Service Broker performs asynchronous operations In asynchronous processing, you send a request to something and then you start doing something else; the system processes the request you made later Between the time when you make the request and when the system process acts on it, the request must be stored somewhere The place where these requests are stored is called the queue • Service Broker implements queues via a hidden table in the database where the queue is defined Service Broker Architecture • Queue: Service Broker Architecture • Services: A Service Broker service identifies an endpoint of a conversation • A service is associated with a list of contracts that is accepted by the service Note that mapping a service to a contract is an optional step on the initiator • On the target, if you not specify any contract, you won’t be able to send any messages to the target Service Broker Architecture • Conversation: • A conversation is a reliable, ordered exchange of messages The core concept of Service Broker is the conversation • Two kinds of conversations: • Dialog: This is a two-way conversation between exactly two endpoints An endpoint is a source or destination for messages associated with a queue; it can receive and send messages A dialog is established between an initiator and target endpoint • Monolog: This is a one-way conversation between a single publisher endpoint and any number of subscriber endpoints Monologs are not available in SQL Server 2005 or 2008, though they will be included in future versions Service Broker Architecture ... Bulk XML data • Overview of SQL Server Integration Services • Using the Import/Export Wizard • Service Broker Introduction • A common task when working with a database is importing data from... Integration Services itself • Integration Services object model • Integrated Services runtime • Integrated Services dataflow Overview of SQL Server Integration Services • Integration Services:... logic and execution of SSIS packages • include packages, containers, pre-defined and custom tasks, and event handlers • The run time handles execution order, logging, variables, and event handling
- Xem thêm -

Xem thêm: Bài giảng Cơ sở dữ liệu nâng cao Chapter 4 Transferring data and using service broker, Bài giảng Cơ sở dữ liệu nâng cao Chapter 4 Transferring data and using service broker, Bài giảng Cơ sở dữ liệu nâng cao Chapter 4 Transferring data and using service broker

Gợi ý tài liệu liên quan cho bạn

Nhận lời giải ngay chưa đến 10 phút Đăng bài tập ngay