Administering SQL Server 2000 - Level 1
Administering SQL Server 2000 - Level 1
This book is designed for those programmers or database administrators (DBA) who wish to learn to use SQL Server 2000.
Assumptions
To be able to use this book effectively it is assumed that you have some previous experience using database management systems (DBMS). You should be familiar with the basics of database terms and normalization. It is also assumed, that you own a copy of SQL Server 2000.
Installation Instructions
To install the samples for each of the chapters, simply create a new folder on your hard drive and copy all of the folders from the floppy disk to this new folder. Under this new folder on your hard drive you will find several folders, each one relating to those chapters in the book that have samples. Each folder is labeled with the chapter number and a short description of what the samples relate to.
Table.sql Creates the tables for the employee system. Insert.sql Adds the data to the tables. Foreign Adds foreign keys to the tables. Index.sql Adds some Indexes to the tables. StoredProc.sql Adds some stored procedures.
Chapter Objectives
1. Learn about the features of SQL Server
You need support for entity, domain, referential and business-policy integrity. You want security enforced at the database level. Ease of installation, deployment and use. SQL Server is by far the easiest database system to install, deploy to users on a Windows 95/98 system. It is extremely easy to use with the wide variety of wizards available and the great graphical tools. Scalability SQL Server can scale from a single user system on a Windows 95/98 platform all the way to an enterprise wide usage with thousands of users across a wide area network. Data Warehousing With new features built in for on-line analytical processing (OLAP), SQL Server is ready to house your largest databases and be able to retrieve that data in a timely and easy format. An english query processor will help your users ask questions of the database and get the correct answers back. Integration with other OS Services SQL Server easily integrates with other Windows NT services such as NT security, email, the internet and other services. XML Support SQL Server has great XML support. It can retrieve data in an XML format, and, with a little help from some system procedures, it can use XML to modify data in a database.
1.3 Transact-SQL
Transact-SQL is the SQL-Server dialect of the SQL language that drives the SQL Server engine. Transact-SQL is a superset of the ANSI 92 standard SQL language. TransactSQL provides powerful extensions to the SQL language, giving users of SQL Server the ability to perform the following: Define stored procedures, remote stored procedures, triggers, rules, column defaults, user-defined data types, etc. Declare variables and use them within the different objects in the SQL Server environment. Control the flow of SQL statements with branching and looping constructs. Perform transaction processing. Enforce data integrity. Transact-SQL goes beyond the ANSI standard by offering more than 35 new or enhanced statements, more than 60 system and utility functions, and over 70 built-in, system-level stored procedures that reside within SQL Server and can be called from front-end applications.
This is a piece of code that you can assign to one or many columns that will check the data being assigned to a column. This is like a rule, but is specifically attached to just one column. SQL Server allows you to define your own user-defined data types that can be used to create columns in a table. You can create your own functions out of existing T-SQL statements and functions.
1.5 Security
SQL Server has the ability to enforce many levels of security. Security Level Description NT Authentication You can authenticate users via their NT login. This way users logging into NT will be automatically authenticated in the SQL Server service as well. SQL Server Authentication You can authenticate users via SQL Server authentication. You may need to do this is users might be coming in from the Internet and are not logged into your NT network. Roles SQL Server pre-defines a certain amount of server roles where the logins assigned to those roles have certain permissions to perform operations within the server. There are also pre-defined database roles for each database created. It is up to you as a system administrator to assign logins to those roles. Users Besides being authenticated to login to the server, you will also make a login a user of a database. This way only certain logins can get to certain databases.
Permissions
After the user has been validated into a database, they can be further granted rights to the objects within that database. Permission Description Table You can grant users of the database the rights to SELECT, INSERT, UPDATE and DELETE from one or many tables in your database. Columns You can grant users rights to just certain columns within a table. Stored Procedures You can grant users rights to execute one or many stored procedures.
Views
You can grant the same rights to views as you can for tables.
1.6 Services
There are at least two services installed with a SQL Server installation; MSSQLServer and SQLServerAgent. These are actual NT services when SQL Server is installed on an NT machine. These services are simulated when installed on Windows 95/98. For these services to run on NT, they must be assigned to a Windows NT user account. Both these services may be assigned to the same user account. Service Description MSSQLServer This is the relational database management system itself. It processes all of the SQL statements and manages all of the files. All of the other services extend the functionality of this service. SQLServerAgent This service helps SQL Server schedule tasks, and checks the alerts to see if any events have been recorded that need attention by an operator. MSDTC The distributed transaction coordinator can help you perform a twophase commit between different SQL Server machines, or even between SQL Server and Oracle. Search This optional service will perform the full-text searching capabilities of SQL Server. This allows you to perform some advanced queries against textual data in your server. You can assign one of three different types of accounts to these services; either a local system, local user, or a domain user account. It is recommended that you use a domain user account that is a member of the Administrators group. The reason for this is the local system and local user accounts do not have network access rights. This could be important if you need to interact with other SQL Servers or other NT servers for some remote services. These types of services that might require a domain user account would be: Replication from one machine to another. When setting up replication it is recommended that you use the same user account for all servers that will be in the replication process (Publishers and Subscribers). Backing up your databases to a network drive. Performing heterogeneous joins that involve remote data sources. If you wish to use the SQL Server Agent mail features and SQL Mail. Executing remote procedure calls (RPCs).
Help
There are several help files installed with SQL Server. Help Description SQL Server Books Online This is the main help that you will probably use most often. This help system will give you a complete overview of the SQL Server database system as well as specific help on how to perform the maintenance duties using the SQL Server Enterprise Manager, T-SQL or the SQL-DMO objects. T-SQL Help This help file gives you complete syntax information on the Transact-SQL language used by SQL Server. Enterprise Manager Help This help file gives you information on how to use the SQL Server Enterprise Manager menus and toolbars. Query Analyzer Help This help file gives you information on how to use the Query Analyzer menus and toolbars. If you press Shift-F1 after highlighting an SQL Statement in the query analyzer window you will bring up the T-SQL help. Profiler Help This help file gives you information on how to use the Profiler menus and toolbars.
1.7 Capacities
Like any database system, SQL Server has its limitations. The following table is a list of those limits: Object Limits Databases per server 32,767 databases. Size of database Over 1 million terabytes. Tables per database 2 billion tables per database. Columns per table 1024 Rows per table Limited only by available storage Bytes per row 8060. This does not include text and image data types. File size of data 32 TB File size of log data 32 TB Column names & variable 128 characters name length Indexes per table 1 clustered index per table. 249 nonclustered indexes per table. A composite index may have up to 16 columns. Triggers per table Limited only by the number of objects in a database Stored procedures Can have up to 255 parameters, and can nest up to 16 levels
User connections
Replication
SQL Server allows you to replicate data from one server to another when the data changes, or at regularly scheduled times. You are allowed to replicate not only to another SQL Server, but any OLE DB data source.
Import/Export Capabilities
SQL Server has the most complete import/export facility of any database system on the market. In fact it even kills a lot of the third party products that perform data transformations from one system to another. You are given complete control over the source and destination of the process. You can even write VBScript code if you need to control the process at the row and/or the column level.
Job Scheduling
SQL Server has a complete scheduling system that will help you schedule tasks that need to run at specified intervals of time. These jobs you might schedule include backups, verifying the integrity of the database, replication, and maybe even publishing data to a web server.
Full-Text Indexing
Allows you to store important words from your character or text data types. You can then perform complex word pattern matching to retrieve rows of data.
English Query
This tool allows users to type in english sentences to query your database. For example you might express a query such as How many employees had sales over $5000 last month? This would return a list of employee names.
Summary
SQL Server 7.0 is an extremely easy database system to use while providing extreme power and flexibility for the most demanding database jobs.
Review Questions
1. Which operating systems will SQL Server run on? a). Linux, Windows and OS/2 b). Any version of Windows 95/98/NT/2000 c). All versions of Windows, plus OS/2. d). None of the above
2. Name the two graphical tools that you will use most often. a). SQL Enterprise Manager and SQL Query Analyzer b). SQL Query Analyzer and SQL Service Manager c). SQL Service Manager and SQL Enterprise Manager d). None of the above.
3. What is Transact-SQL? a). An SQL command that starts a transaction. b). A stored procedure. c). A dialect of the SQL language defined to run on the SQL Server engine. d). None of the above.
4. What is the main storage area for all your tables and other objects called? a). Database b). Table c). Column d). None of the above.
5. What does the SQLServerAgent service do? a). Schedules tasks and checks alerts b). Helps you perform a two phase commit between different SQL Server
machines c). Performs full text searching d). Process all SQL Server SQL statements