Tài liệu MASTERING SQL SERVER 2000- P3 ppt

50 357 0
Tài liệu MASTERING SQL SERVER 2000- P3 ppt

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

DB-Library Options Tab One of the features that makes SQL Server such a powerful tool is the variety of meth- ods that you can use to retrieve data from it. You can execute Transact-SQL code using tools such as Query Analyzer or the OSQL command line tool, or you can write your own custom programs. DB-library is one of the tools available for writing custom pro- grams using a language like C++ or Visual Basic. DB-library is an application program- ming interface (API), which is a collection of functions and commands that developers can access through their own code. Using APIs, developers do not need to rewrite code that Microsoft has already writ- ten. This makes the developer’s job much easier. As Microsoft makes changes and updates to the code in SQL Server, the DB-library API gets upgraded, which means that you may occasionally need to get a new copy from the Microsoft Web site. To ascertain which version of the API you have loaded on your system, check the DB- library information box at the top of the DB-Library Options tab. This tells you the version, size, and date of the DB-library file you are using. Not only can you view the version of the DB-library installed on your machine using the DB-Library Options tab, you can also set two options that can change the way your DB-library works: Automatic ANSI to OEM Conversion: This setting will allow the DB- library to convert data from the client (OEM) into data that SQL Server will understand (ANSI) and vice versa. Use International Settings: This setting will allow the DB-library to get date, time, and currency formats from the server, instead of you having to hard code the formats into all your applications. CHAPTER 3 • OVERVIEW OF SQL SERVER 70 2627ch03.qxt 8/22/00 9:57 AM Page 70 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 71 Network Libraries Tab The sole function of the Network Libraries tab is to display the version number and date of the network library files that you have installed on your local system. If your files are out of date, you can upgrade them by installing the latest service pack (dis- cussed in Chapter 1). The best way to tell whether these files are out of date is to check your version numbers on the Network Libraries tab and compare them with the version numbers that Microsoft posts in the service pack readme file. A readme file will contain information on all of the fixes and new file versions that come with the service pack. Server Network Utility The Server Network Utility, located in the Microsoft SQL Server 2000 group in the Pro- grams group on the Start menu, works much the same as the Client Network Utility in that it is used to configure the net-libraries on which the server listens. The biggest dif- ference that you may notice is the addition of the WinSock Proxy information. With this proxy information, you can configure SQL Server to listen for client calls over the Internet through a Microsoft Proxy Server. All you need to do is check the Enable WinSock Proxy checkbox and supply the IP address or computer name of the proxy server as well as the port number for the proxy server to listen on. The Network Libraries tab here performs the same function as the Network Libraries tab in the Client Network Tool. PROGRAMS INSTALLED WITH SQL SERVER Introducing SQL Server PART I 2627ch03.qxt 8/22/00 9:57 AM Page 71 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Service Manager Having only one function, the Service Manager is a simple tool compared to the rest. The Service Manager exists to start, stop, pause, and monitor the status of your SQL Server services. The easiest way to get to this tool is by double-clicking the small server icon in your Taskbar tray—or you can get to it from the SQL Server 2000 group in Programs on the Start menu. Once opened, this tool can be used to start, stop, or pause any of the four SQL Server services. Distributed Transaction Coordinator: Primarily used to control trans- actions that are distributed between multiple servers, this service is covered in Chapter 8. MSSQLServer: This service is the heart of SQL Server, because it performs such functions as executing queries, managing access to data, and allocating system resources (such as RAM and CPU). SQLServerAgent: This service will be discussed in detail in Chapter 14, but it controls automation. This service will execute tasks (such as backing up a database) and send e-mail in the event of a problem. Microsoft Search: This service creates and maintains full-text search indexes. These indexes allow users to perform faster searches on fields of the text datatype. We’ll discuss full-text search in Chapter 6. CHAPTER 3 • OVERVIEW OF SQL SERVER 72 2627ch03.qxt 8/22/00 9:57 AM Page 72 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 73 NOTE When you look at the icon in the system tray, you will notice a green arrow, which means your service is running. If the arrow is red, your service is stopped. Yellow means paused. TIP You can also perform Service Manager operations by right-clicking the Service Man- ager icon in the system tray. Profiler Once you have successfully designed and deployed your databases, and your users are accessing them on a regular basis for inserting, updating, and deleting data, you need to monitor the server to make sure it is running the way it is supposed to. You need to know such things as how fast the server is running, what sort of data the users are accessing, and whether anyone is trying to hack into your server. In the SQL Server 2000 group in the Programs group on the Start menu, you will find Profiler, a powerful monitoring tool that can show you all of this information and a great deal more. Using Profiler involves setting up event-monitoring protocols, called traces. An event is anything that happens to a running system, such as a failed or successful login, a query being properly routed and the results retrieved, or a report being run. You can design each trace to look at specific aspects of the system, which you’ll get a PROGRAMS INSTALLED WITH SQL SERVER Introducing SQL Server PART I 2627ch03.qxt 8/22/00 9:57 AM Page 73 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. chance to do in Chapter 26. By monitoring events, you can tell how the system is being used and whether anything needs tweaking for greater efficiency. NOTE For more information on using SQL Profiler, see Chapter 24. Query Analyzer In Start ➣ Programs ➣ SQL Server 2000, you will find Query Analyzer, a graphic tool that allows you to execute collections of Transact-SQL statements, called queries. Most of the queries executed in Query Analyzer will be SELECT queries, designed to display data stored in your database tables. Other examples of queries that you can execute here might be DELETE queries, designed to remove data from your database, or INSERT queries, which add data. Some of the queries you execute with this tool will not modify your data; rather, they will modify the structure that holds your data. These types of queries are referred to as data definition statements, and they are used to accomplish such tasks as creating tables, indexes, views, users, etc. Any Transact-SQL code that you need to run can be executed using this tool. However, that is only half of what it does. CHAPTER 3 • OVERVIEW OF SQL SERVER 74 2627ch03.qxt 8/22/00 9:57 AM Page 74 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 75 NOTE Throughout this book, you will see the term query, which is a term used to describe a request for data from SQL Server. This request is made using Transact-SQL state- ments, usually a SELECT statement (which is designed specifically for the purpose of retrieving data). Query Analyzer not only executes Transact-SQL queries, it analyzes them as well (thus the name). The analysis will tell you such things as how much CPU time the query took to run, how much time it spent reading from the hard disk, etc. Once you know how much time and resources your queries take to run, you can tune them accordingly. If your queries run too slowly, you can rewrite them to make them run faster (that discussion is in Chapter 6). If you take a look at Figure 3.1, you will see a picture of Query Analyzer displaying the results of a query for all of the records in the Authors table of the pubs database. The top half of the screen contains the actual SELECT query, and the bottom half of the screen contains the results of that query, called the result set. FIGURE 3.1 Query Analyzer is used to execute Transact-SQL code and display the results. PROGRAMS INSTALLED WITH SQL SERVER Introducing SQL Server PART I 2627ch03.qxt 8/22/00 9:57 AM Page 75 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. NOTE When you first open Query Analyzer, you will see the Object Browser. We have closed it for many of the examples in this book for the sake of simplicity. You’ll learn how to use Query Analyzer in more detail in Chapter 5. OSQL OSQL is a command line tool that executes Transact-SQL code and displays the results, just like Query Analyzer. Aside from the fact that Query Analyzer is graphical and OSQL is a command line tool, there is only one small difference between the two: OSQL does not have the ability to analyze queries and display statistics on speed of execution. Other than that, the two tools perform much the same function, executing Transact-SQL code. This begs the question, “Why use OSQL if you have Query Ana- lyzer?” The answer is scheduling. Suppose that you have a sales manager who needs to see daily figures on sales. Because you cannot schedule Query Analyzer to run a command automatically, you would need to instruct the manager how to execute a query in Query Analyzer so that they could manually extract the data every night. Not many managers out there have this kind of time on their hands, though. Another method you could consider is creating a job to automate the task. A job is a series of steps that can be executed automatically by SQL Server. One of those steps could be the query that extracts the data your manager needs, but there is no way to get that data from a job to the manager. OSQL can be used to run the query and save the data to a text file. The command can also be scheduled (using such tools as the Windows NT AT command or a SQL Server job) to run automati- cally. The manager can then read the text file whenever they want. NOTE OSQL runs in one of two modes: interactive or batch. Interactive mode func- tions much like Query Analyzer in that it allows you to enter commands at a prompt, and when you finish, you type EXIT. Batch mode sends a single command to the server and returns a result set. Batch mode is used for automation. Several arguments can be used to control the behavior of the OSQL program. All of them are case-sensitive, which means that an uppercase E means something entirely different than a lowercase e. The arguments that you can use are listed here: -Uusername: To send queries to a SQL Server, you must gain access by log- ging in. There are two ways to log in. One way is by using a trusted connection, CHAPTER 3 • OVERVIEW OF SQL SERVER 76 2627ch03.qxt 8/22/00 9:57 AM Page 76 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 77 which means that SQL Server trusts Windows NT to verify your username and password. The second way is by establishing a nontrusted connection, which means that SQL Server must verify your username and password. The -Uuser- name parameter tells SQL Server which user to log you in as using a nontrusted connection. Therefore, if you want to log in as a user named Bob, the -U para- meter would look as follows: -Ubob. -Ppassword: This specifies the case-sensitive password to be used in con- junction with the -U parameter. If you are logging in as Bob and your password is doughnut, the -P parameter would look as follows: -Pdoughnut. -E: This specifies a trusted connection, where SQL Server trusts Windows NT to verify your username and password. This requires no username or password to be entered because OSQL will detect the username and password you used to log on to your computer, and use that same information to log you in to SQL Server. -Sserver_name: This specifies the name of the server that you want to con- nect to in order to perform queries. The -Slondon parameter, for example, would connect you to a server named london. -L: If you cannot remember the name of the server you want to connect to in order to query, the -L parameter detects all of the SQL Servers on the network and displays a list for you. -e: This parameter will repeat (or echo) the commands that you type. If you enter a query, for example, it will be repeated on the first line of the result set. -p: This parameter will print performance statistics about the query executed. It displays execution time, extracted records per second, and network packet size. -n: In interactive mode, you normally see line numbers before each line of text that you type as well as a > symbol. The -n parameter removes the line numbers and the > symbol. -ddb_name: This sets the database with which you will be working. If you want to query one of the tables in the pubs database, for example, this parame- ter would be -dpubs. -Q“query”: This will execute the query encased in quotation marks and immediately exit the OSQL program. Note that queries must be encased in double quotes. -q“query”: This also executes the query in quotes, but does not exit OSQL after execution. Once the query is finished, you remain in interactive mode. -ccmd_end: Ordinarily, when working in interactive mode, you must enter the word GO on a line by itself to tell OSQL that you have finished entering PROGRAMS INSTALLED WITH SQL SERVER Introducing SQL Server PART I 2627ch03.qxt 8/22/00 9:57 AM Page 77 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. code and it should be executed now. This is called a command terminator. Using this parameter, you can set a different command terminator. -hheaders: By default, you will see the names of the columns in the result set printed only once, at the top of the result set. If this is not enough, you can use the -h command to print the header more often. The -h5 parameter reprints the names of the columns (the headers) every five lines. -wcolumn_width: The default number of characters that are displayed on a single line of output is 80. The -w parameter changes that to be more or fewer characters. For example, -w70 would display only 70 characters on a line of output. -scol_separator: The default method of separating columns on the screen is to use a blank space. Because this may be difficult for some people to read, you can change the separator using the -s parameter. For instance, -s> would sepa- rate your columns from one another using the > symbol. -ttimeout: If a command fails while it is running (for example, the SQL Server goes down), the command will run indefinitely by default. To change that behavior, you can specify a timeout parameter. For example, -t5 would instruct OSQL to time out after waiting 5 seconds for a response. -merror_level: SQL Server recognizes several levels of error severity from 1 to 25; 1 is the lowest (reserved by SQL Server), 10 is informational (something happened, but it’s not too bad), and 25 is the highest (your server is having a stroke). The -m parameter tells OSQL which levels to display; for instance, -m10 displays all level 10 errors and higher, but nothing lower. -I: In interactive mode, you ordinarily place strings of text inside single quotes (‘’). With this option set, you can encase text strings in double quotes instead (“”). -r {0 | 1}: Because not all error messages are printed to the screen, you can use this parameter to redirect them to the screen. The parameter -r0 will display error messages of 17 or higher, and -r1 will display all messages on the screen. -Hwksta_name: With this parameter, you can specify the name of the com- puter from which you are connecting. The default for this is the computer name. However, if you are on a Windows NT machine that has both a com- puter name (used by other Microsoft machines) and a hostname (used by Unix machines and other TCP/IP hosts), you can instruct OSQL to connect as your hostname rather than your machine name. CHAPTER 3 • OVERVIEW OF SQL SERVER 78 2627ch03.qxt 8/22/00 9:57 AM Page 78 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 79 -R: Various settings control the process of converting currency, date, and time values into character data to be displayed on the screen. The -R setting instructs OSQL to use the client settings rather than the server settings to per- form this conversion. -iinput_file: SQL Server can accept a text file as an input parameter by using the -i parameter. This means that you can enter all of your settings and your query in a text file (using something like Notepad), and then, instead of enter- ing all of the information on the command line every time, you can specify an input file. -ooutput_file: This will copy the result set to a text file, as opposed to the screen (which is the default). The -oc:\output.txt parameter, for instance, copies the result set from your query to a file named output.txt. -u: This is used in conjunction with the -o parameter to specify that the out- put file be stored as Unicode data rather than ASCII (the standard character set that displays 256 characters). This is useful for companies that store data in multiple languages. -apacket_size: This specifies the amount of data (in kilobytes) that SQL Server will send to or receive from OSQL at a time, called a packet of data. The default size is 512KB, which works fine for most transfers, but if you are performing a bulk insert of data from a large text file into a table, you may want to increase this to 8192 (Microsoft recommends this based on their testing). -b: This parameter instructs OSQL to exit to DOS and return a DOS error level of 1 when a problem arises. DOS error levels can be used in batch files for troubleshooting. -O: This forces OSQL to behave more like its precursor, ISQL. This parameter sets the default DOS ERRORLEVEL value to –1 and specifically turns off the fol- lowing features: EOF batch processing Automatic console width scaling Wide messages -ltimeout: This specifies the amount of time that OSQL will wait for a login to be verified. If this parameter is not specified, OSQL will wait indefinitely. -?: This parameter will display a list of all the available switches to be used with OSQL. PROGRAMS INSTALLED WITH SQL SERVER Introducing SQL Server PART I 2627ch03.qxt 8/22/00 9:57 AM Page 79 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. [...]... order or organization to them—if SQL Server simply wrote data wherever Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark 8/22/00 9:57 AM Page 99 SQL SERVER STORAGE CONCEPTS it found the space It would take forever for SQL Server to find your data when you asked for it, and the entire server would be slow as a result To keep this from happening, SQL Server has even smaller levels... Indexing Wizard, click Next Introducing SQL Server 10 On the final screen of the Wizard, you are given a summary of the choices you have made Click Finish to create the index Now that you have a better understanding of some of the things SQL Server stores in a database, you should know how it stores them Let’s peer into the depths of SQL Server s storage concepts SQL Server Storage Concepts Just like any... know a little bit about how SQL Server writes data to disk When a user wants to make changes to data in your table, SQL Server does not write that change directly to the data file Instead SQL Server extracts the data to be modified from the data file and places it in memory Once the data is in memory, the user can make changes Every now and then (about every 5 minutes), SQL Server takes all the changes... R T I Introducing SQL Server 2627ch03.qxt 2627ch03.qxt 88 8/22/00 9:57 AM Page 88 CHAPTER 3 • OVERVIEW OF SQL SERVER To access SQL Server, users must have what is called a login account There are two types of login accounts that you can give to your users: standard and integrated An integrated account is also referred to as a trusted connection, because with this type of login, SQL Server trusts Windows... to default settings It is also used to view DB-library version information Server Network Utility: This is used to view and change network library settings on the server It can also view DB-library version information Service Manager: This is used to start, stop, or pause the four services used by SQL Server: MSSQLServer, SQLServerAgent, MSDTC, and MSSearch Profiler: This tool is used to monitor events... 3 • OVERVIEW OF SQL SERVER Fortunately, you do not need to specify every parameter listed here to make OSQL work Let’s look at using OSQL to run a query and save the results to a text file: 1 To get to the command prompt, click your Start button, select Programs, and click the Command Prompt icon 2 To execute a query with OSQL, type the following command at the command prompt: OSQL –Sserver_name –dpubs... would work fine except for one small problem: If one of your users entered XZ as a state, SQL Server would accept it, because it is a character value By using constraints, you could have SQL Server check the data that is being entered against a list of acceptable values—the constraints—which means that when SQL Server encountered XZ, which is not a valid state abbreviation, it would reject the update... imagine the havoc that would be wreaked on your bandwidth Another problem caused by ad hoc queries is that they can also slow SQL Server down When an ad hoc query is sent to SQL Server the first time, it cannot be executed right away; it must first be compiled To compile a query, SQL Server must read the query and figure out the fastest way to execute it by comparing the query to the available indexes The... same table or index, are scattered throughout the database file To avoid fragmentation, SQL Server assigns space to tables and indexes in extents That way, at least eight of the pages should be physically next to one another, making them easier for SQL Server to locate There are actually two types of extents that SQL Server uses to organize pages: uniform and mixed Uniform extents are those entirely owned... www.verypdf.com to remove this watermark 8/22/00 9:57 AM Page 101 SQL SERVER STORAGE CONCEPTS Mixed extents are used for objects that are too small to fill eight pages by themselves In that instance, SQL Server will divvy up the pages in the extent to multiple objects Figure 3.8 shows the difference between uniform and mixed extents FIGURE 3.8 SQL Server uses uniform and mixed extents to further organize space . distributed between multiple servers, this service is covered in Chapter 8. MSSQLServer: This service is the heart of SQL Server, because it performs such. Analyzer is used to execute Transact -SQL code and display the results. PROGRAMS INSTALLED WITH SQL SERVER Introducing SQL Server PART I 2627ch03.qxt 8/22/00

Ngày đăng: 24/12/2013, 02:17

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan