1. Trang chủ
  2. » Công Nghệ Thông Tin

Tài liệu MASTERING SQL SERVER 2000- P23 pdf

50 325 0
Tài liệu đã được kiểm tra trùng lặp

Đ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

Thông tin cơ bản

Tiêu đề Transact-SQL Reference
Trường học University of Technology, Ho Chi Minh City
Chuyên ngành Database Management
Thể loại Tài liệu hướng dẫn
Năm xuất bản 2000
Thành phố Ho Chi Minh City
Định dạng
Số trang 50
Dung lượng 0,95 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

In this chapter, we are going to present the instructions for installing SQL Server 2000 so that you need to do it only once.. The Prerequisites There are a few things that you will need

Trang 1

T hroughout the book, you’ve seen examples of Transact-SQL (T-SQL)

state-ments Nearly every SQL Server operation can be performed using SQL from a graphical interface such as Query Analyzer or even from thecommand line using OSQL This includes operations such as setting up jobsand alerts for which we demonstrated only the Enterprise Manager steps

Transact-In this appendix, we’ve presented all of the SQL statements that we discussedexplicitly in this book For each statement, we include the entire syntax and a cross-reference to the chapter where that statement is discussed in more depth

Creating a Database

CREATE DATABASE statement (Chapter 10):

CREATE DATABASE database_name

ON [PRIMARY]

(

NAME=logical_file_name, FILENAME=’os_file_name’, SIZE=size (in MB or KB), MAXSIZE=maximum_size (in MB or KB) or UNLIMITED (fill all available space), FILEGROWTH=growth_increment (in MB or KB)

)LOG ON (

NAME=logical_file_name, FILENAME=’os_file_name’, SIZE=size (in MB or KB), MAXSIZE=maximum_size (in MB or KB) or UNLIMITED, FILEGROWTH=growth_increment (in MB or KB)

)[ FOR LOAD | FOR ATTACH ]

Cursor Statements

DECLARE CURSOR statement (Chapter 8):

DECLARE cursor_name [INSENSITIVE][SCROLL] CURSOR FOR select_statement

[FOR {READ ONLY | UPDATE [OF column_name [,…n]]}]

Trang 2

DECLARE cursor_name CURSOR

[LOCAL | GLOBAL]

[FORWARD_ONLY | SCROLL]

[STATIC | KEYSET | DYNAMIC | FAST_FORWARD]

[READ_ONLY | SCROLL_LOCKS | OPTIMISTIC]

[TYPE_WARNING]

FOR select_statement [FOR UPDATE [OF column_name [ ,…n]]]

OPEN statement (Chapter 8):

OPEN {{[GLOBAL] cursor_name} | cursor_variable_name}

FETCH statement (Chapter 8):

FETCH[[ NEXT | PRIOR | FIRST | LAST

| ABSOLUTE {n | @n_variable}

| RELATIVE {n | @n_variable}

]FROM]

{{[GLOBAL] cursor_name} | @cursor_variable_name}

[INTO @variable_name [,…n]]

CLOSE statement (Chapter 8):

CLOSE {{[GLOBAL] cursor_name} | cursor_variable_name}

DEALLOCATE statement (Chapter 8):

DEALLOCATE {{[GLOBAL] cursor_name} | cursor_variable_name}

Database Options

ALTER DATABASE statement (Chapter 5):

ALTER DATABASE database_name

SET {SINGLE_USER | RESTRICTED_USER | MULTI_USER} |{OFFLINE | ONLINE} |

{READ_ONLY | READ_WRITE} |CURSOR_CLOSE_ON_COMMIT {ON | OFF} |CURSOR_DEFAULT {LOCAL | GLOBAL} |

Trang 3

AUTO_CREATE_STATISTICS ON | OFF } |AUTO_SHRINK ON | OFF } |

AUTO_UPDATE_STATISTICS ON | OFF } |ANSI_NULL_DEFAULT { ON | OFF } |ANSI_NULLS { ON | OFF } |ANSI_PADDING { ON | OFF } |ANSI_WARNINGS { ON | OFF } |ARITHABORT { ON | OFF } |CONCAT_NULL_YIELDS_NULL { ON | OFF } |NUMERIC_ROUNDABORT { ON | OFF } |QUOTED_IDENTIFIERS { ON | OFF } |RECURSIVE_TRIGGERS { ON | OFF } |RECOVERY { FULL | BULK_LOGGED | SIMPLE } |TORN_PAGE_DETECTION { ON | OFF } [,…n]

sp_dbcmptlevel statement (Chapter 5):

sp_dbcmptlevel [[@dbname=] ‘database_name’]

[,[@new_cmptlevel=] version]

sp_dboption statement (Chapter 5):

sp_dboption [[@dbname=] ‘database_name’]

TRUNCATE TABLE statement (Chapter 7):

TRUNCATE TABLE table_name

Trang 4

| expression }[,…n] )

| derived_table

| execute_statement

}}

| DEFAULT VALUES

SELECT INTO statement (Chapter 7):

SELECT select_list INTO new_table_name FROM table_source [WHERE condition]

[GROUP BY expression]

HAVING condition]

[ORDER BY expression]

Retrieving Records

SELECT statement (Chapter 6):

SELECT [ALL | DISTINCT]

[{TOP integer | TOP integer PERCENT} [WITH TIES]]

Trang 5

[GROUP BY [ ALL ] group_by_expression [,…n]

[WITH { CUBE | ROLLUP }]

[HAVING search_condition]

[ORDER BY { order_by_expression | column_position [ASC | DESC]] [OPTION ( < query_hint > [ ,…n ])]

Rowsets

CONTAINSTABLE statement (Chapter 8):

CONTAINSTABLE (table_name, {column_name | *},

<simple_term> ::=

word | “phrase”

Trang 6

ISABOUT ({{

BEGIN TRANSACTION statement (Chapter 8):

BEGIN TRANS[ACTION] [transaction_name | @name_variable]

[WITH MARK [‘description’]]

COMMIT TRANSACTION statement (Chapter 8):

COMMIT TRANS[ACTION] [transaction_name | @name_variable]

@savepoint_variable]

ROLLBACK [WORK]

SAVE TRANSACTION statement (Chapter 8):

SAVE TRANS[ACTION] {savepoint_name | @savepoint_variable}

FREETEXTTABLE statement (Chapter 8):

FREETEXTTABLE (table_name, {column_name | *},

Trang 7

table_name [WITH (table_hint […n])]

| view_name

| OPENQUERY | OPENROWSET | OPENDATASOURCE}

SET{

column_name = {expression | DEFAULT | NULL}

UPDATETEXT statement (Chapter 7):

UPDATETEXT {table_name.dest_column_name dest_text_ptr} { NULL | insert_offset }

{ NULL | delete_length }

[WITH LOG]

[

inserted_data | {table_name.source_column_pointer source_text_ptr}

]

WRITETEXT statement (Chapter 7):

WRITETEXT {table.column text_ptr}

[WITH LOG] {data}

Trang 8

User-Defined Functions

CREATE FUNCTION statement (Chapter 5):

CREATE FUNCTION [owner_name].function_name

Trang 10

APPENDIX B

Installing Microsoft SQL Server 2000

F E A T U R I N G : The Prerequisites 1130 The Setup Wizard 1131 The Client Software 1142 Unattended Setup 1142 Upgrading from a Previous Version 1143 Installing SQL Server Yourself 1150 Installing a Second Instance 1151 The Desktop Database Engine 1153

Trang 11

H ave you ever bought something whose instructions read, “Some assembly

required”? What was the first thing you did with it when you got home?

If you’re like most people, you opened the box, scattered the parts on thefloor, and tried to find pieces that looked like they fit together In theend, you probably had a huge mess on your hands and a burning desire to read theinstructions that came with the product

SQL Server 2000 should have a sign right on the front of the box that reads, “Someassembly required” just to remind you that you need to read the instructions first, notlast Just like with the product you bought, with SQL Server, if you read the instruc-tions after the install, you will end up with a mess This mess is not easy to clean up,though; in some instances, you may even need to reinstall SQL Server

In this chapter, we are going to present the instructions for installing SQL Server 2000

so that you need to do it only once We’ll start by looking at the prerequisites—whatsort of hardware and software need to be in place before you can even think aboutinstalling SQL Server Then we’ll move into installing SQL Server itself, examiningeach step of the Setup Wizard and pointing out things to which you need to pay spe-cial attention Once SQL Server is installed, we’ll look at an alternative method ofinstallation: the unattended install Because there are so many of you out there whowill be upgrading from a previous version of SQL Server, we are also going to lookinto the upgrade process Finally, because not all installs go perfectly, we’ll look intosome troubleshooting techniques to ensure that SQL Server gets up and running

The Prerequisites

There are a few things that you will need in place on your machine before you will beable to install SQL Server 2000, the first of which is Internet Explorer 4 SP1 or higher.Many people have cowered in terror at this thought, believing that SQL Serverrequires this program to serve up data That is not the case The only parts of SQLServer 2000 that require IE4 are the Microsoft Management Console (discussed later)and HTML help (Books Online)

The minimum hardware requirements and the recommendations (what youshould actually use) are listed in Table B.1

Trang 12

TABLE B.1: THE REQUIREMENTS

Memory RAM (32MB minimum) More is better but at least 128Disk drive CD-ROM drive

Network software

Now that you have the hardware and software in place, you can start the SetupWizard You’ll do that by inserting the CD and selecting Install SQL Server Compo-nents, then selecting the appropriate version The Standard version is for use on Win-dows NT Server; the Desktop version is a scaled-down version that will run onWindows NT Workstation and Windows 95/98 Once you have selected your version,the Setup Wizard takes over and guides you through installation

The Setup Wizard

Before you run the Setup Wizard, which we’ll do later, there are a few things you’llneed to understand, so in this section, we’ll look at each of the steps in the Setup Wiz-ard; then, later on, you’ll get to put this knowledge to use by installing SQL Server onyour own machine

Windows 2000, NT, or 95/98 built-innetwork software; additional networksoftware is not required unless you areusing Banyan Vines or AppleTalk ADSP;

Novell NetWare client support is vided by NWLink

pro-Be sure to get the latestservice pack

Microsoft Windows 2000 family; Microsoft Windows NT 4 family with SP5; Microsoft Windows 95/98; Windows 95 OSR2Operating system

Don’t forget that you needenough space to store data-bases

190MB (Full); 163MB (Typical); 74MB(Minimum); 73MB (management tools only)

Hard-disk space

The fastest possible sor; multiple if your budgetallows

proces-DEC Alpha AXP; Intel Pentium 133 Mhz

or higher; or compatible systemsComputer

Installing Microsoft S QL Server 2

A P PB

Trang 13

NOTE There are two editions of SQL Server 2000: Standard and Enterprise Enterprise istuned for much larger databases and runs on Windows NT Enterprise Edition or 2000Advanced Server Although the following steps apply to either edition, we will use Standard.

After the welcome screen, you are asked whether this installation is to be a local,remote, or virtual installation (as seen in Figure B.1):

Local Computer: This option will install SQL Server on the machine whereyou are running the setup program

Remote Computer: Selecting this option will allow you to install SQLServer on any machine on the network on which you have administrativeauthority You could, for example, sit at a machine in San Francisco and installSQL Server on a machine in Chicago

Virtual Server: SQL Server can be set up in a cluster, which means that

mul-tiple machines act as a single machine—this can be very useful for load ing and fault tolerance The option to set up a virtual server is for clusteringsupport To use this option, you must have clustering support already installed

balanc-FIGURE B.1

The Computer Name

screen

Trang 14

As shown in Figure B.2, the next screen you run into will present four choices:

• The first option will allow you to create a brand-new instance of SQL Server

We’ll discuss instances shortly

• The second choice presented will allow you to upgrade or add components to

an existing installation

• The third choice will allow you to maintain a virtual server in a cluster

• The final option will allow you to record a file for unattended installations (discussed later in this chapter)

FIGURE B.2

You have four installation types from which to choose.

The next two screens that pop up will ask you for a user and company name, andagreement to the license terms When these steps are complete, the screen shown inFigure B.3 appears, where you are asked what you would like to install There are threechoices available:

Client Tools Only: This option will install only the client tools necessaryfor connecting to SQL Server, such as Query Analyzer and Enterprise Manager

Server and Client Tools: This will install the client tools as well as the SQLServer services This option is what actually turns your machine into a SQL Server

Installing Microsoft S QL Server 2

A P PB

Trang 15

Connectivity Only: This option will install just the network librariesneeded to connect to SQL Server If you use this option, you will need a customprogram, such as Access or Visual Basic, to access the data on the server.

set or sort order (now referred to as collation settings), you can run multiple instances

of SQL Server on one machine Your clients will see each instance as a completely arate installation of SQL Server

sep-The Default instance is selected by default (no pun intended) and should be leftthat way for the first installation of SQL Server Subsequent installations on the samemachine can be given installation names of up to 32 characters Clients will then usethis new name to refer to the new instance

On the next screen, you will be asked where you would like to install your program

files, which are the SQL Server executable files (called binaries), and where you would

like to store your data files, which are your system and user databases Before you pick

a directory, there is an important decision to be made If you are upgrading and you

Trang 16

install over the top of the old version (the default), you will not be able to switch backand forth between the two versions; if you place the new version in a new directory,you can switch between the new and old versions of SQL Server This capability canprove invaluable for troubleshooting applications that may not be compatible withSQL Server 2000 just yet.

You also have the choice of performing a Typical, Minimum, or Custom install (asshown in Figure B.4) With Custom, you can install whatever features you like; thedifferences between Typical/Custom and Minimum are listed in Table B.2

FIGURE B.4

The Setup Type screen

TABLE B.2: THE INSTALL TYPES

Install client management tools All None

Installing Microsoft S QL Server 2

A P PB

Trang 17

TABLE B.2: THE INSTALL TYPES (CONTINUED)

If you opt for the Custom install type, you will see the screen that shows up in ure B.5, asking you which components should be installed We’ll select the defaultsand take you to the next screen, where you must pick a service account

Fig-FIGURE B.5

Setup allows you

to choose the components you want to install.

Choosing Service Accounts

When you first turn on your Windows NT/2000 machine and try to use it, you are sented with a dialog box that asks you for a username and password That username

pre-TCP/IP Sockets andMultiprotocol

TCP/IP Sockets andMultiprotocol

Configure network protocols(Windows 95 and Windows 98)

Named Pipes, TCP/IPSockets, and Multiprotocol

Named Pipes, TCP/IPSockets, andMultiprotocolConfigure network protocols

(Microsoft Windows NT)

Trang 18

and password allow you access to the machine (and the network) with whatever leges your administrator has seen fit to assign Many services, programs running in thebackground, require a user account just like you do This special user account, called a

service account, allows the service access to the machine and network with the

privi-leges the service requires to get its work done The dialog box used to assign such anaccount to SQL Server is shown in Figure B.6

TABLE B.3: USER ACCOUNTS

Allows you to communicatefully with other networkmachines, including SQL

None; slightly more difficult to configurethan the other two

Global User

Allows you to control theservice permissions withoutallowing network access

You will not be able to communicatewith other SQL Servers over the network

Local User

Easy to set up, because youneed not create a useraccount

You will not be able to communicatewith other SQL Servers over the network

Local System

Installing Microsoft S QL Server 2

A P PB

Trang 19

If you opt to use a user account (local or global), you must first create it using theappropriate tool for your operating system If you create only one account to be used

by both MSSQLServer and SQLServerAgent services (discussed earlier in this book),you must add the user account to the Administrators local group; otherwise, replica-tion (also discussed earlier) will not function properly If you decide you would likegreater control over the security on your network, you can add two separate accounts,one for the MSSQLServer service and one for the SQLServerAgent service A very goodreason to do this is that only the SQLServerAgent service really requires administra-tive authority; the other service can get by just fine as a user

Once you have selected a service account, you are asked to set the tion mode

authentica-Authentication modes are discussed in detail in Chapter 18, but it is good to know

a little about them for setup purposes To access SQL Server, your users need to log in

to the server To log in to the server, they need an account The type of account theyuse depends upon the authentication mode that is set If you select Windows Authen-tication mode, only clients that have a Windows NT/2000 account will be able toaccess the system If you have other clients (such as Novell or UNIX), you shouldselect Mixed mode

After selecting a mode, you can click Next You will then be asked for a collationsetting

Choosing a Collation Setting

In previous versions of SQL Server, it was necessary to choose a character set, a sortorder, and a Unicode collation setting In SQL Server 2000, these three entities have

been combined to form the collation setting There are two types of collation settings

to choose from: Windows Collation and SQL Collation

SQL Collation is for backward compatibility with older versions of SQL Server anddoes not control Unicode character storage If you need to replicate with older ver-sions of SQL Server or will be switching between SQL Server 2000 and older versions,you should use SQL Collation If you are installing SQL Server 2000 on a machinewith an older version of SQL Server installed, the setup program will detect the neces-sary SQL Collation for you; otherwise you will need to select the proper collation.Windows Collation uses the collation (code page, sort order, etc.) of the underlyingoperating system and controls Unicode and non-Unicode sorting and storage If youchoose Windows Collation, you have two more things to worry about: the collationdesignator and the sort order

Trang 20

Selecting a Collation Designator

As you read this book, you see the characters as lines, curves, and various shapes Ifyou read Cyrillic, you see different shapes for the characters than does someone read-ing German or English Computers need to read and interpret characters just like youdo—the only problem is that computers don’t see them as various shapes; they seethem as different combinations of ones and zeros It makes sense then that if yourcomputer is storing German data, your computer must store different characters, orcombinations of ones and zeros, than an English server would How these characters

are stored is controlled by the collation designator.

If you decide to use Windows Collation, it is best to use the collation of the lying operating system; for example, if you are running a German server, you wouldmost likely choose a German collation designator The easiest way to find your colla-tion designator is to look in Control Panel under Regional Options; the locale dis-played there should be used as your collation designator

under-Selecting a Sort Order

All of the data that you are storing on your server must be sorted from time to time,usually during queries or indexing You sort data because looking at a mass of jumbleddata is hard on the brain, whereas looking at a nicely ordered report of data is easy and

pleasing to the eye The sort order defines how SQL Server sorts and compares your data

during queries This sort order is the second part of the collation setting

There are four sort options available, even though you see only three The first isthe default sort order—case-insensitive and accent-insensitive This means that SQLServer will not pay attention to case or accent marks when sorting, indexing, or per-forming queries The remaining three options can change this behavior, and if youare familiar with previous versions of SQL Server, you will want to pay attentionbecause the options have changed:

Binary: Using the default sort order, SQL Server will view characters as acters; by using binary sort order, SQL Server will view characters as binary rep-resentations This is the fastest sort order available, but it is case-sensitive andaccent-sensitive

char-Case Sensitive: This simply tells SQL Server to use dictionary sort order andpay attention to case

Accent Sensitive: This tells SQL Server to use dictionary order and payattention to accent marks

Here’s the catch: Once you have installed SQL Server, you cannot change the tion setting To change it, you must reinstall SQL Server and rebuild all of your data-

colla-Installing Microsoft S QL Server 2

A P PB

Trang 21

and build sensitivity into your applications if you feel the need for it Figure B.7shows the Collation Settings dialog box where all of these choices are made.

FIGURE B.7

The Collation Settings

screen

Choosing Network Libraries

You should already have some protocols installed on your computer, but unfortunately,SQL Server can’t see them right away You have to tell SQL Server how to use the proto-cols you have by installing network libraries There are several to choose from:

Named Pipes: Enabled by default, this network library will allow you to useNamed Pipes connections over all three of Microsoft’s protocols (NetBEUI,NWLink, and TCP/IP) This is required on the server, because client software(i.e., Enterprise Manager) uses it to connect to the server service

TCP/IP: TCP/IP is an industry-standard protocol that SQL Server supportswhen this library is installed, which happens by default Although SQL Serverrelies on the operating system for configuration options, such as the IP address,subnet mask, and default gateway, SQL Server will automatically start listeningfor network traffic on TCP port 1433

Multiprotocol: This library will support Interprocess CommunicationsMechanisms (IPCs) over all three of Microsoft’s protocols and supports its ownencryption This library should be used for backward compatibility only; SSLencryption should be used to replace it

Trang 22

IPX/SPX: A popular protocol in the Novell world, IPX/SPX is supported bythis network library When you install it, you can even configure what namethe NetWare clients will use to access your server; this should be the same asyour NetBIOS name to avoid confusion.

AppleTalk: This library will allow your Macintosh clients to access yourdata It is good to migrate from AppleTalk to TCP/IP, because Microsoft willsoon be removing this library

Banyan Vines: Banyan Vines is a network operating system (like NT) thatuses SPP (Sequenced Packet Protocol) as its primary protocol With this library,your Banyan Vines clients can access the SQL Server Again, you should migrate

to TCP/IP as soon as possible, because there will soon be no support for thislibrary

Down at the very bottom of the screen (shown in Figure B.8), you will notice anoption that is new to SQL Server 2000: Enable Protocol Encryption for All Libraries

This will allow SQL Server to encrypt data over any net-library by using SSL To usethis new feature, you need to have a few things in place before installation First, youneed a certificate from a certificate authority such as Verisign or even Microsoft’s Cer-tificate Server You will also need to be sure that all of your clients are running thenew net-libraries that come with SQL Server 2000, because the older libraries don’tunderstand SSL encryption

If you’re worried about selecting the wrong network libraries, you can stop ing You may select network libraries without trepidation, because you can changethem after setup using the Server Network Utility

Trang 23

After this last step, SQL Server will ask you for licensing information and startcopying files Afterward you will have a fancy new SQL Server Now it is time to lookinto some of the custom setups that can be performed.

The Client Software

Many users make the mistake of thinking of client software as the Visual Basic orAccess application with which your users gain access to the data That is not the case;when Microsoft discusses client software, they mean things such as the following:

of your SQL Servers from a central location To install these programs, you need onlyrun the Setup Wizard and select the Client Tools Only option

If you have multiple servers to install, running the Setup Wizard manually can betime-consuming To save time, you may want to consider the unattended method

Sql70cli.bat: This command will install only the client software, includingEnterprise Manager, Query Analyzer, etc

Sql70cst.bat: This will install all of the SQL Server components It uses thelocal system account for the services

Sql70ins.bat: This is a typical install It too uses the local system accountfor the services

Trang 24

Sql70rem.bat: This is designed to perform an unattended removal of SQLServer.

Deskecst.bat: This is the custom install for Windows 95/98

Deskeins.bat: This performs a typical install on Windows 95/98

If one of these does not meet your needs, you can record your own You mayremember that one of the functions the setup program can perform is recording anunattended installation file If you want a custom installation file, all you need to do

is run setup and select the option to record an unattended installation file This willcreate the necessary ISS file without actually installing SQL Server Then, all you need

to do is run the following command:

start /wait X:\x86\setup\setupsql.exe -f1 C:\SQL7.iss -SMS –sThe start /wait command is a DOS command that instructs the computer not toreturn control to the command prompt until the running program is finished execut-ing The SMS switch tells the SQL setup program not to return control to the com-mand prompt until it is completely done Of course, the rest of the command linetells setup where the configuration file is located Armed with this knowledge, youwill be able to perform an unattended install Now we are ready to discuss upgrades

Upgrading from a Previous Version

If you are upgrading from a previous version, as many of you may be, you have a fewoptions from which to choose You can use the Upgrade Wizard, or you can perform aside-by-side upgrade

The Upgrade Wizard

The Upgrade Wizard is usually invoked during the setup program itself, but if youhave decided to leave your older version of SQL Server in place so that you mayswitch back in case of a problem, you will need to run the Upgrade Wizard at a latertime In the next series of steps, you are going to upgrade a SQL Server 6.5 database byusing the Upgrade Wizard:

1 Go to the SQL Server Switch group under Programs on the Start menu and select

SQL Server Upgrade Wizard A welcome screen comes up; here, we’ll click Next

Installing Microsoft S QL Server 2

A P PB

Trang 25

2 On the next screen, you’ll find the Data and Object Transfer; this is where you

tell SQL Server what you want upgraded from SQL Server 6.x to 2000 You can

also instruct SQL Server to verify the transfer; a standard verification will onlycompare the number of rows after a transfer, whereas an exhaustive verificationwill perform a checksum value on each column before transfer Select ValidateSuccessful Object Data Transfer here, but not Exhaustive, and click Next

Ngày đăng: 26/01/2014, 08:20