home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft_Programmers_Library.7z / MPL / net / sqladm.txt < prev    next >
Encoding:
Text File  |  2013-11-08  |  445.9 KB  |  13,319 lines

  1.  Microsoft SQL Server - System Administrator's Guide
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  ────────────────────────────────────────────────────────────────────────────
  11.             Microsoft(R) SQL Server - System Administrator's Guide
  12.  
  13.               The SYBASE(R) SQL Server database for PC networks
  14.                                  VERSION 1.1
  15.  ────────────────────────────────────────────────────────────────────────────
  16.  
  17.  
  18.                      for the MS(R) OS/2 Operating System
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  Microsoft Corporation
  28.  
  29.  Information in this document is subject to change without notice and does
  30.  not represent a commitment on the part of Microsoft Corporation. The
  31.  software described in this document is furnished under a license agreement
  32.  or nondisclosure agreement. The software may be used or copied only in
  33.  accordance with the terms of the agreement. It is against the law to copy
  34.  the software on any medium except as specifically allowed in the license or
  35.  nondisclosure agreement. No part of this manual may be reproduced or
  36.  transmitted in any form or by any means, electronic or mechanical, including
  37.  photocopying and recording, for any purpose without the express written
  38.  permission of Microsoft Corporation.
  39.  (C) 1990 Microsoft Corporation and SYBASE, Inc. All rights reserved.
  40.  
  41.  
  42.  Printed in the USA.
  43.  
  44.  
  45.   1 = Microsoft, MS-DOS, MS, and the Microsoft logo are registered trademarks
  46.  of Microsoft Corporation.  IBM is a registered trademark of International
  47.  Business
  48.  Machines Corporation.
  49.  
  50.  
  51.  SYBASE is a registered trademark of SYBASE, Inc.
  52.  TRANSACT-SQL and DB-LIBRARY are trademarks of SYBASE, Inc.
  53.  
  54.  Document Number: SY10229-0290
  55.   OEM-D/0788-1Z
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  Table of Contents
  63.  ────────────────────────────────────────────────────────────────────────────
  64.  
  65.  
  66.  
  67.  Before You Begin
  68.       Manual Overview
  69.       How to Use This Guide
  70.       Notational Conventions
  71.       Finding Further Information
  72.  
  73.  Chapter 1  Overview of System Administration
  74.  
  75.       Introduction
  76.       Special Users of SQL Server
  77.              System Administrator
  78.              Database Owner
  79.              Database Object Owner
  80.       SQL Server Administration Tools
  81.              SQL Server Administration Facility
  82.              TRANSACT-SQL Statements
  83.              System Procedures
  84.              Help on TRANSACT-SQL Statements and System Procedures
  85.              Utility Programs
  86.              Batch Files and the isql Utility Program
  87.       System Tables
  88.              Permissions on System Tables
  89.              Querying System Tables
  90.              Keys in System Tables
  91.       System Databases
  92.              The master Database
  93.              The model Database
  94.              The tempdb Database
  95.              The pubs Sample Database
  96.  
  97.  Chapter 2  Using the SAF
  98.  
  99.       Introduction
  100.       Starting the SAF
  101.       Responding to Messages
  102.       Menus and Dialog Boxes
  103.       Menus and Menu Items
  104.       Dialog Boxes
  105.              Text Boxes
  106.              List Boxes
  107.              Option Buttons
  108.              Command Buttons
  109.              Display Fields
  110.       Getting Help
  111.       Exiting the SAF
  112.  
  113.  Chapter 3  Making Queries with the SAF
  114.  
  115.       Introduction
  116.       About the Examples
  117.       Queries and Results
  118.              Queries
  119.              Results
  120.       The Window Menu
  121.       Creating Queries
  122.              Entering Queries
  123.              Scrolling
  124.              Selecting and Deleting Text
  125.       Executing Queries
  126.       Viewing the Results of Queries
  127.              Viewing the Query and Results on Separate Screens
  128.              Scrolling the Results Window
  129.              Alternating between Different Windows
  130.       Modifying Previous Queries and Results
  131.       Making a New Query
  132.       Saving Queries and Results
  133.              Filenames for Query and Results Files
  134.              Saving Queries or Results to a File
  135.       Working with Saved Queries and Results
  136.       Printing Queries and Results
  137.       Logging Queries and Results to a File
  138.       Logging In to Another Server
  139.  
  140.  Chapter 4  Starting and Shutting Down SQL Server
  141.  
  142.       Introduction
  143.       Starting SQL Server
  144.              Starting SQL Server Using the SAF (MS OS/2 Only)
  145.              Starting SQL Server Using the net Command
  146.       Shutting Down SQL Server
  147.              Shutting Down SQL Server Using the Config Menu
  148.              Shutting Down SQL Server Using the SHUTDOWN Statement
  149.              Shutting Down SQL Server Using the net Command
  150.  
  151.  Chapter 5  Managing Storage
  152.  
  153.       Introduction
  154.       Dumping the master Database
  155.       Adding Database Devices and Dump Devices
  156.              Database Devices and Dump Devices
  157.              Adding Database Devices
  158.              Setting Up Default Database Devices
  159.              Adding Dump Devices
  160.              Displaying Information on Database Devices and Dump Devices
  161.       Creating Databases and Transaction Logs
  162.              Creating a Database
  163.              Putting the Transaction Log into a Different Database Device
  164.              Expanding the Transaction Log Space
  165.              Altering Database Size
  166.              Displaying Information on Database Storage
  167.              How SQL Server Allocates Space for a Database
  168.       Dropping Databases
  169.       Dropping Database Devices and Dump Devices
  170.  
  171.  Chapter 6  Managing User Accounts
  172.  
  173.       Introduction
  174.       Managing Login IDs
  175.              Login IDs and Passwords
  176.              Special Login IDs
  177.              Default Databases
  178.              Visitor Login IDs
  179.              Managing Login IDs Using the Admin Menu
  180.              Managing Login IDs Using System Procedures
  181.              Displaying Information on Login IDs
  182.       Managing Database Usernames
  183.              Usernames
  184.              Guest User
  185.              Managing Usernames Using the Admin Menu
  186.              Managing Usernames Using System Procedures
  187.              Displaying Information on Usernames
  188.       Managing Database Groups
  189.              Groups
  190.              Public Group
  191.              Managing Database Groups Using the Admin Menu
  192.              Managing Groups Using System Procedures
  193.              Displaying Information on Groups
  194.       Managing Aliases
  195.              Aliases
  196.              Managing Aliases Using the Admin Menu
  197.              Managing Aliases Using System Procedures
  198.              Displaying Information on Aliases
  199.       Changing a Database Owner
  200.              Changing a Database Owner Using the Admin Menu
  201.              Changing a Database Owner Using System Procedures
  202.              Displaying Information on Database Owners
  203.       Displaying Information on Current Users
  204.  
  205.  Chapter 7  Managing User Permissions
  206.  
  207.       Introduction
  208.       Permissions Summary
  209.       Object and Statement Permissions
  210.       The Permission Hierarchy
  211.              Permissions of the SA
  212.              Permissions of Database Owners
  213.              Permissions of Database Object Owners
  214.              Permissions on System Tables
  215.              Permissions on System Procedures
  216.              The SETUSER Statement
  217.       Granting and Revoking Permissions
  218.              GRANT and REVOKE Statements
  219.              Combining GRANT and REVOKE Statements
  220.              Conflicting GRANT and REVOKE Statements
  221.              Displaying Information on Permissions
  222.       Permissions on Views and Stored Procedures
  223.              Views as Security Mechanisms
  224.              Stored Procedures as Security Mechanisms
  225.              Ownership Chains
  226.              Triggers
  227.  
  228.  Chapter 8  Backup and Recovery
  229.  
  230.       Introduction
  231.       Automatic Recovery
  232.       Transaction Logs
  233.       Checkpoints
  234.       Dumping a Database or Transaction Log
  235.              When to Dump Databases
  236.              Dump Devices
  237.              Dumping a Database
  238.              Dumping a Transaction Log
  239.              Truncating a Transaction Log
  240.              Interactions between Backing Up a Database and Its Log
  241.       Loading a Database
  242.              Loading a Database Using the Admin Menu
  243.              Loading a Database Using System Procedures
  244.       Loading a Transaction Log
  245.              Loading a Transaction Log Using the Admin Menu
  246.              Loading a Transaction Log Using System Procedures
  247.              Keeping Transaction Logs Small
  248.              If You Run Out of Space in a Database
  249.       Moving a Database
  250.       Restoring the master Database
  251.              Building the master Database
  252.              Starting SQL Server in Single-User Mode
  253.              Adding a Dump Device
  254.              Reloading the master Database
  255.              Applying Changes
  256.       Recovering from Media Failure
  257.              Re-creating Lost Devices and Reloading Lost Databases
  258.              Finding Information on Lost Devices and Databases
  259.              Examples of Recovery from Media Failure
  260.  
  261.  Chapter 9  Fine-tuning Performance and Operations
  262.  
  263.       Introduction
  264.       Setting Query Options
  265.       Setting and Changing Database Options
  266.              Displaying Information on Database Options
  267.       Monitoring SQL Server Activity
  268.       Updating Statistics
  269.       Locking and the HOLDLOCK Keyword
  270.              Displaying Information on Locking
  271.              HOLDLOCK Keyword
  272.              Deadlocks and Livelocks
  273.       Setting Configuration Options
  274.              Configuration Options
  275.              Changing Configuration Options Using the Config Menu
  276.              Changing Configuration Options Using System Procedures
  277.              Displaying Information on Configuration Options
  278.  
  279.  Chapter 10  Transferring Data to and from SQL Server
  280.  
  281.       Introduction
  282.       Permissions Needed to Copy Data
  283.       Transferring Data with the Bulk Copy Utility
  284.              Native and Character Options
  285.              Changing the Defaults: Interactive bcp
  286.              File Storage Type
  287.              Prefix Length
  288.              Length
  289.              Field Terminator
  290.       Indexes
  291.       Data Integrity: Defaults, Rules, and Triggers
  292.       Example of Copying a Database Table to a File
  293.              Copying Data for Use with Other Programs
  294.       Example of Copying a File to a Database Table
  295.       Error Files
  296.  
  297.  Chapter 11  Diagnosing System Problems
  298.  
  299.       Introduction
  300.       Error Log
  301.       Error Messages
  302.              Message Numbers
  303.              Severity Levels
  304.       Reporting Errors
  305.       Stopping Processes
  306.       Database Consistency Checker
  307.              The CHECKTABLE Option
  308.              The CHECKDB Option
  309.              The CHECKALLOC Option
  310.              The CHECKCATALOG Option
  311.              The DBREPAIR Option
  312.  
  313.  Appendix A  The pubs Sample Database
  314.  
  315.              A.1.1
  316.              Rules
  317.              Trigger
  318.              Stored Procedure
  319.              View
  320.              Defaults
  321.  
  322.  Appendix B  System Tables
  323.  
  324.              sysalternates (all databases)
  325.              syscolumns (all databases)
  326.              syscomments (all databases)
  327.              sysconfigures (master database only)
  328.              syscurconfigs (master database only)
  329.              sysdatabases (master database only)
  330.              sysdepends (all databases)
  331.              sysdevices (master database only)
  332.              sysindexes (all databases)
  333.              syskeys (all databases)
  334.              syslocks (master database only)
  335.              syslogins (master database only)
  336.              syslogs (all databases)
  337.              sysmessages (master database only)
  338.              sysobjects (all databases)
  339.              sysprocedures (all databases)
  340.              sysprocesses (master database only)
  341.              sysprotects (all databases)
  342.              syssegments (all databases)
  343.              systypes (all databases)
  344.              sysusages (master database only)
  345.              sysusers (all databases)
  346.  
  347.  Appendix C  Special Keys
  348.  
  349.              Editing Keys (Dialog Boxes)
  350.              Editing Keys (SQL Windows)
  351.              Menu Keys
  352.              Query Keys
  353.  
  354.  Index
  355.  
  356.  
  357.  
  358.  
  359.  Before You Begin
  360.  ────────────────────────────────────────────────────────────────────────────
  361.  
  362.  
  363.  Manual Overview
  364.  
  365.  This manual explains the various tools and techniques used to manage SQL
  366.  server databases. It is written for System Administrators who are
  367.  responsible for maintaining systems running SQL Server.
  368.  
  369.  Before using this manual, you should be familiar with TRANSACT-SQL(tm),
  370.  which is described in SQL Server Learning TRANSACT-SQL and in the SQL Server
  371.  Language Reference. You should also be familiar with MS-DOS(R) and Microsoft
  372.  Operating System/2 (MS(R) OS/2) system management.
  373.  
  374.  
  375.  How to Use This Guide
  376.  
  377.  The following topics are covered in this manual:
  378.  
  379.  ────────────────────────────────────────────────────────────────────────────
  380.  Chapter 1
  381.    An overview of system and database administration
  382.  
  383.  Chapter 2
  384.    Instructions for using the System Administration Facility (SAF)
  385.  
  386.  Chapter 3
  387.    Information on creating queries with the SAF
  388.  
  389.  Chapter 4
  390.    Instructions for starting and stopping SQL Server
  391.  
  392.  Chapter 5
  393.    Information on managing storage
  394.  
  395.  Chapter 6
  396.    Information on managing user accounts
  397.  
  398.  Chapter 7
  399.    Information on managing user permissions
  400.  
  401.  Chapter 8
  402.    Instructions for database backup and recovery
  403.  
  404.  Chapter 9
  405.    Information on performance tuning
  406.  
  407.  Chapter 10
  408.    Information on transferring data to and from SQL Server
  409.  
  410.  Chapter 11
  411.    Help with diagnosing system problems
  412.  
  413.  Appendix A
  414.    A description of the structure of the pubs sample database
  415.  
  416.  Appendix B
  417.    A description of the various system tables
  418.  
  419.  Appendix C
  420.    Special keys recognized by SAF
  421.  
  422.  ────────────────────────────────────────────────────────────────────────────
  423.  Notational Conventions
  424.  
  425.  Throughout this manual, the following conventions are used to distinguish
  426.  elements of text:
  427.  
  428. ╓┌─────────────────────────────────┌─────────────────────────────────────────╖
  429.  Convention                        Purpose
  430.  ────────────────────────────────────────────────────────────────────────────
  431.  UPPERCASE                         Represents statement and clause names,
  432.                                    functions, macros, and any other
  433.                                    portions of syntax that must appear
  434.                                    exactly as shown.
  435.  
  436.  SMALL CAPS                        Represent key names such as CTRL.
  437.  
  438.  bold                              Represents stored procedures, system
  439.                                    procedures, triggers, defaults, rules,
  440.                                    utility programs, and commands.
  441.  
  442.  italic                            Represents database names, table names,
  443.  Convention                        Purpose
  444.  ────────────────────────────────────────────────────────────────────────────
  445. italic                            Represents database names, table names,
  446.                                    view names, column names, datatypes,
  447.                                    index names, pathnames, filenames, and
  448.                                    variables that appear in text.
  449.  
  450.  monospace                         Represents examples, screen output,
  451.                                    program code, and error messages.
  452.  
  453.  [brackets]                        Enclose optional items. Type only the
  454.                                    information within the brackets, not the
  455.                                    brackets themselves.
  456.  
  457.  {braces}                          Enclose required items. Type only the
  458.                                    information within the braces, not the
  459.                                    braces themselves.
  460.  
  461.  | (vertical bar)                  Separates items inside a set of braces
  462.                                    or brackets. The vertical bar means you
  463.                                    must choose one and only one item.
  464.  Convention                        Purpose
  465.  ────────────────────────────────────────────────────────────────────────────
  466.                                   must choose one and only one item.
  467.  
  468.  ... (ellipsis)                    Means that you can repeat the previous
  469.                                    item as many times as you like.
  470.  
  471.  <execute>                         Executes one or more SQL statements. (In
  472.                                    the SQL Server Administration facility,
  473.                                    SQL statements are executed by pressing
  474.                                    the CONTROL+E keys. In the isql program,
  475.                                    SQL statements are executed with the go
  476.                                    command.)
  477.  
  478.  ────────────────────────────────────────────────────────────────────────────
  479.  
  480.  
  481.  
  482.  
  483.  Finding Further Information
  484.  
  485.  The following manuals describe SQL Server and are included in the standard
  486.  documentation set:
  487.  
  488.  ────────────────────────────────────────────────────────────────────────────
  489.  SQL Server Installation Guide
  490.    A guide to installing and setting up SQL Server
  491.  
  492.  SQL Server Learning TRANSACT-SQL
  493.    A guide to learning and using TRANSACT-SQL
  494.  
  495.  SQL Server Language Reference
  496.    A reference to the syntax of all TRANSACT-SQL statements, commands,
  497.    procedures, and utilities
  498.  
  499.  SQL Server Programmer's Reference
  500.    A reference to DB-LIBRARY(tm), which is a set of C routines and macros
  501.    that allow your application to interact with SQL server
  502.  
  503.  SQL Server Quick Reference
  504.    A quick reference guide to TRANSACT-SQL
  505.  
  506.  ────────────────────────────────────────────────────────────────────────────
  507.  
  508.  
  509.  
  510.  
  511.  Chapter 1  Overview of System Administration
  512.  ────────────────────────────────────────────────────────────────────────────
  513.  
  514.  
  515.  Introduction
  516.  
  517.  This chapter describes
  518.  
  519.  
  520.    ■   The special users who are responsible for managing SQL Server
  521.        databases
  522.  
  523.    ■   The tools used to manage SQL Server databases
  524.  
  525.    ■   SQL Server system tables
  526.  
  527.    ■   SQL Server system databases
  528.  
  529.  
  530.  Many of the procedures discussed in this document require you to be logged
  531.  in as the System Administrator (SA). To identify yourself to SQL Server as
  532.  the SA, use the login ID sa and the password that is assigned to the SA.
  533.  
  534.  
  535.  Special Users of SQL Server
  536.  
  537.  Three types of special users manage and control SQL Server:
  538.  
  539.  
  540.    ■   The System Administrator
  541.  
  542.    ■   Database Owners
  543.  
  544.    ■   Database Object Owners
  545.  
  546.  
  547.  
  548.  System Administrator
  549.  
  550.  The SA is not necessarily an individual; rather, system administration is a
  551.  role. Anyone who knows the SA's password can log in and act as the SA. In a
  552.  large organization, the SA's role can be carried out by several people or
  553.  groups.
  554.  
  555.  The SA is responsible for administrative tasks unrelated to specific
  556.  applications. Typically, the SA does the following:
  557.  
  558.  
  559.    ■   Installs SQL Server
  560.  
  561.    ■   Manages storage
  562.  
  563.    ■   Creates user databases and grants ownership of them
  564.  
  565.    ■   Sets up user accounts on SQL Server
  566.  
  567.    ■   Grants permissions to SQL Server users
  568.  
  569.    ■   Backs up system data and restores it in case of failure
  570.  
  571.    ■   Transfers bulk data between SQL Server and other software programs
  572.  
  573.    ■   Diagnoses system problems
  574.  
  575.    ■   Fine-tunes SQL Server by changing the configuration options
  576.  
  577.  
  578.  For information on installing SQL Server, see the SQL Server Installation
  579.  Guide. The other system administration tasks listed above are described in
  580.  this guide.
  581.  
  582.  When SQL Server is installed, the SA is the Database Owner of the master
  583.  database. The SA is also treated as the Database Owner of any databases he
  584.  or she uses.
  585.  
  586.  
  587.  Login ID and Password
  588.  
  589.  The SA's login ID is sa. Immediately after installation, the SA has no
  590.  password: that is, the password is the null value. As long as the SA has no
  591.  password, anyone can log in as sa.
  592.  
  593.  ────────────────────────────────────────────────────────────────────────────
  594.  NOTE
  595.  
  596.  After SQL Server has been installed, be sure to change the SA's password and
  597.  to control knowledge of it. See Chapter 6, "Managing User Accounts," for
  598.  instructions on changing passwords.
  599.  ────────────────────────────────────────────────────────────────────────────
  600.  
  601.  More than one person in an organization can be authorized to log in as sa.
  602.  However, it is important that the SA's administrative functions be
  603.  centralized or well coordinated.
  604.  
  605.  
  606.  Permissions
  607.  
  608.  Unlike other users, the SA has permission to use all TRANSACT-SQL
  609.  statements, system procedures, and menus in the SQL Server Administration
  610.  Facility (SAF). For detailed information on SA permissions, see Chapter 7,
  611.  "Managing User Permissions."
  612.  
  613.  
  614.  Database Owner
  615.  
  616.  A Database Owner creates a database and is then responsible for
  617.  administrative tasks related to that database. These tasks include
  618.  
  619.  
  620.    ■   Adding users to the database
  621.  
  622.    ■   Assigning users to groups
  623.  
  624.    ■   Granting permissions within the database
  625.  
  626.    ■   Creating tables
  627.  
  628.    ■   Creating procedures, rules, defaults, triggers, and views
  629.  
  630.    ■   Backing up and restoring the database
  631.  
  632.  
  633.  The Database Owner owns the database and all its system tables.
  634.  
  635.  
  636.  Login ID and Password
  637.  
  638.  A Database Owner logs in to SQL Server using his or her normal login ID and
  639.  password. The Database Owner's username within the database is always dbo.
  640.  This name is automatically assigned when the database is created.
  641.  
  642.  
  643.  Permissions
  644.  
  645.  The Database Owner has full permissions inside the database he or she owns
  646.  and must grant permissions to other users before they can access the
  647.  database. For example, the Database Owner can give particular SQL Server
  648.  users specified levels of access to the database and add a guest account to
  649.  give all SQL Server users limited access to it. The Database Owner is
  650.  responsible for granting other users permission to create tables, views,
  651.  rules, defaults, and stored procedures.
  652.  
  653.  The Database Owner can also set up groups, which are used for convenience in
  654.  granting and revoking permissions.
  655.  
  656.  
  657.  Database Object Owner
  658.  
  659.  A user who creates a database object is its owner. Before creating a
  660.  database object, permission to create that object must be granted by the
  661.  Database Owner.
  662.  
  663.  
  664.  Database Objects
  665.  
  666.  Each SQL Server database is a set of database objects. These database
  667.  objects include the following:
  668.  
  669. ╓┌─────────────────────────────────┌─────────────────────────────────────────╖
  670.  Database Object                   Description
  671.  ────────────────────────────────────────────────────────────────────────────
  672.  Default                           A value that SQL Server inserts into a
  673.                                    column if the user does not enter a
  674.  Database Object                   Description
  675.  ────────────────────────────────────────────────────────────────────────────
  676.                                   column if the user does not enter a
  677.                                    value
  678.  
  679.  Index                             An ordered set of pointers to the data
  680.                                    in a table
  681.  
  682.  Rule                              A specification controlling what data
  683.                                    can be entered in a column
  684.  
  685.  Stored procedure                  A precompiled collection of SQL
  686.                                    statements
  687.  
  688.  Table                             A collection of rows and columns
  689.  
  690.  Trigger                           A special form of stored procedure that
  691.                                    goes into effect automatically when a
  692.                                    user modifies data in a table
  693.  
  694.  View                              An alternate way of looking at data in
  695.  Database Object                   Description
  696.  ────────────────────────────────────────────────────────────────────────────
  697. View                              An alternate way of looking at data in
  698.                                    one or more tables
  699.  
  700.  ────────────────────────────────────────────────────────────────────────────
  701.  
  702.  
  703.  
  704.  For complete information on database objects, see SQL Server Learning
  705.  TRANSACT-SQL.
  706.  
  707.  
  708.  Login ID and Password
  709.  
  710.  A database object owner logs in to SQL Server using his or her normal login
  711.  ID. There is no special login ID or password for database object owners.
  712.  
  713.  
  714.  Permissions
  715.  
  716.  A database object owner must grant permissions to other users before they
  717.  can access the database object.
  718.  
  719.  
  720.  SQL Server Administration Tools
  721.  
  722.  To manage an SQL Server database, you use a combination of SAF menus,
  723.  TRANSACT-SQL statements, and system procedures. You can also develop batch
  724.  files made up of a series of SQL statements.
  725.  
  726.  
  727.  SQL Server Administration Facility
  728.  
  729.  The SAF provides easy-to-use menus, which help you perform many system
  730.  administration tasks, and the SQL Query Window, which you use to execute
  731.  TRANSACT-SQL statements and system procedures.
  732.  
  733.  In many cases, you have a choice: you can perform a task by using a menu or
  734.  by executing SQL statements and system procedures. In some cases, there is
  735.  no menu to perform a task, so you must use SQL statements or system
  736.  procedures.
  737.  
  738.  
  739.  Menus
  740.  
  741.  You can use SAF menus to perform common administrative tasks, such as
  742.  
  743.  
  744.    ■   Adding user accounts
  745.  
  746.    ■   Saving queries and their results to files
  747.  
  748.    ■   Setting configuration options
  749.  
  750.    ■   Shutting down SQL Server
  751.  
  752.  
  753.  See Chapter 2, "Using the SAF," and Chapter 3, "Making Queries with the
  754.  SAF," for details on how to use SAF menus.
  755.  
  756.  
  757.  SQL Query Window
  758.  
  759.  The SQL Query Window allows you to enter, edit, and execute SQL statements
  760.  or system procedures. After you execute the statement or system procedure,
  761.  the results appear at the bottom of the screen. An example of a system
  762.  procedure and its results is shown in Figure 1.1:
  763.  
  764.  (This figure may be found in the printed book.)
  765.  
  766.  See Chapter 2, "Using the SAF," and Chapter 3, "Making Queries with the
  767.  SAF," for details on how to execute SQL statements and system procedures
  768.  from the SQL Query Window.
  769.  
  770.  
  771.  SAF Help
  772.  
  773.  From the SAF Help menu, you can get information on some of the most common
  774.  system administration tasks. Many administrative tasks can be performed by
  775.  using SAF menus; however, some more complex tasks cannot be performed
  776.  through these menus. The SAF Help screens include step-by-step procedures
  777.  that show how to perform these more complex tasks.
  778.  
  779.  See Chapter 2, "Using the SAF," and Chapter 3, "Making Queries with the
  780.  SAF," for details on how to use SAF Help.
  781.  
  782.  
  783.  TRANSACT-SQL Statements
  784.  
  785.  TRANSACT-SQL, the enhanced SQL language, contains many statements used by
  786.  SAs. You execute these statements from the SQL Query Window. TRANSACT-SQL
  787.  statements are described throughout this manual and also in SQL Server
  788.  Learning TRANSACT-SQL and the SQL Server Language Reference.
  789.  
  790.  
  791.  System Procedures
  792.  
  793.  A system procedure is a precompiled collection of SQL statements. Many
  794.  system procedures are available for managing SQL Server and for displaying
  795.  information on databases and users.
  796.  
  797.  System procedures are located in the master database and are owned by the
  798.  SA, but many of them can be executed from any database.
  799.  
  800.  You can write your own system procedures that can be executed from any
  801.  database. See SQL Server Learning TRANSACT-SQL for more information on
  802.  creating your own system procedures.
  803.  
  804.  If a system procedure is executed in a database other than master, it
  805.  operates on the system tables in the database from which it was executed.
  806.  
  807.  System procedures are described throughout this manual and also in SQL
  808.  Server Learning TRANSACT-SQL and the SQL Server Language Reference.
  809.  
  810.  
  811.  Help on TRANSACT-SQL Statements and System Procedures
  812.  
  813.  The sp_helpsql system procedure displays the syntax of TRANSACT-SQL
  814.  statements, system procedures, and other topics. You can use the sp_helpsql
  815.  system procedure as you develop queries. The sp_helpsql system procedure has
  816.  the following syntax:
  817.  
  818.    sp_helpsql ["topic"]
  819.  
  820.  For example, to get help on the DISK INIT statement, execute
  821.  
  822.    sp_helpsql "disk init"
  823.  
  824.  
  825.  Utility Programs
  826.  
  827.  Utility programs are executed from the operating system prompt, not from the
  828.  SAF. SQL Server includes these utility programs:
  829.  
  830. ╓┌─────────────────────────────────┌─────────────────────────────────────────╖
  831.  Utility Program                   Function
  832.  ────────────────────────────────────────────────────────────────────────────
  833.  bcp                               Copies a database table to or from an
  834.                                    operating system file.
  835.  
  836.  bldmastr                          Builds the master database.
  837.  
  838.  console                           Prompts the operator while a database is
  839.                                    being backed up or restored to or from
  840.                                    diskettes. When you use the SAF to back
  841.                                    up or restore a database, you do not
  842.  Utility Program                   Function
  843.  ────────────────────────────────────────────────────────────────────────────
  844.                                   up or restore a database, you do not
  845.                                    need to start the console program.
  846.  
  847.  defncopy                          Copies definitions of database objects
  848.                                    to a file.
  849.  
  850.  isql                              Executes batch files.
  851.  
  852.  ────────────────────────────────────────────────────────────────────────────
  853.  
  854.  
  855.  
  856.  
  857.  Batch Files and the isql Utility Program
  858.  
  859.  The isql utility program executes a batch file which contains one or more
  860.  SQL statements.
  861.  
  862.  You can use the SAF or a text editor to create and save a batch file. Be
  863.  sure to add the go command on a separate line to execute previous SQL
  864.  statements or system procedures.
  865.  
  866.  To execute the batch file, use the isql command at the operating system
  867.  prompt. (See the SQL Server Language Reference for details on isql.)
  868.  
  869.  For example, the following isql command executes a batch file, authors.qry,
  870.  and places the results in the authors.res file:
  871.  
  872.    isql /U sa /P mypassword /S myserver /i authors.qry /o authors.res
  873.  
  874.  
  875.  System Tables
  876.  
  877.  SQL Server system tables keep track of information about SQL Server as a
  878.  whole and about each user database.
  879.  
  880.  All of the SQL-Server-supplied tables in the master database (SQL Server's
  881.  controlling database) are considered system tables. In addition, each user
  882.  database is created with a subset of these system tables.
  883.  
  884.  A master database and its tables are created when SQL Server is installed.
  885.  The system tables in a user database are automatically created when the
  886.  CREATE DATABASE statement is executed.
  887.  
  888.  See Appendix B, "System Tables," for detailed information on each system
  889.  table.
  890.  
  891.  
  892.  Permissions on System Tables
  893.  
  894.  The Database Owner controls permissions for use of the system tables, just
  895.  like permissions on any other tables.
  896.  
  897.  The SQL Server setup program sets up permissions so that all users can read
  898.  necessary information in the system tables.
  899.  
  900.  Direct updates to system tables are not allowed, even for the Database
  901.  Owner. In almost all cases, updates to the system tables should be performed
  902.  using system procedures or SAF menus. To set a configuration option that
  903.  allows direct updates to the system tables, see Chapter 9, "Fine-tuning
  904.  Performance and Operations."
  905.  
  906.  
  907.  Querying System Tables
  908.  
  909.  The system tables can be queried just like any other table. For example,
  910.  here's a statement that returns the names of all triggers in the current
  911.  database:
  912.  
  913.    select name
  914.     from sysobjects
  915.     where type = "TR"
  916.  
  917.  The system procedures provide shortcuts for querying the system tables.
  918.  
  919.  
  920.  Keys in System Tables
  921.  
  922.  Primary, foreign, and common keys for the system tables have been defined in
  923.  the master and model databases. A report on defined keys is available by
  924.  executing the sp_helpkey system procedure. For a report on columns in two
  925.  system tables that are likely join candidates, execute sp_helpjoins.
  926.  
  927.  
  928.  
  929.  System Databases
  930.  
  931.  When SQL Server is installed, it has three databases: the master database,
  932.  model database, and tempdb temporary database. The SA can optionally install
  933.  the pubs sample database.
  934.  
  935.  
  936.  The master Database
  937.  
  938.  The master database controls the user databases and the operation of SQL
  939.  Server as a whole. It keeps track of user accounts, ongoing processes,
  940.  system error messages, the databases on SQL Server, the storage allocated to
  941.  each database, the available database devices and dump devices, and the
  942.  active locks. In addition, the system procedures are stored in master.
  943.  
  944.  You must be in the master database to execute the CREATE DATABASE, DISK
  945.  INIT, DISK REFIT, and DISK REINIT statements.
  946.  
  947.  It is possible to add user objects to the master database, but it's not a
  948.  good idea. Any objects created in master should be used for the
  949.  administration of the system as a whole, so permissions in master should be
  950.  set so that most users cannot create objects there.
  951.  
  952.  Another way to discourage users from creating objects in master is to change
  953.  users' default databases (the database to which the user is connected after
  954.  login). Default databases are discussed in Chapter 6, "Managing User
  955.  Accounts."
  956.  
  957.  ────────────────────────────────────────────────────────────────────────────
  958.  WARNING
  959.  
  960.  You should back up the master database after you change it─each time you
  961.  create a database, alter a database, allocate physical storage, and so on.
  962.  If the master database is damaged, it is recovered with a procedure
  963.  different from that for user databases. (See Chapter 8, "Backup and
  964.  Recovery.")
  965.  ────────────────────────────────────────────────────────────────────────────
  966.  
  967.  
  968.  The model Database
  969.  
  970.  The model database provides a template or prototype for new user databases.
  971.  Each time the CREATE DATABASE statement is executed, SQL Server makes a copy
  972.  of the model database and then extends it to the size requested in the
  973.  CREATE DATABASE statement.
  974.  
  975.  The model database contains the system tables required for each user
  976.  database. It can be modified to customize the structure of newly created
  977.  databases─everything you do to model is reflected in each new database. Here
  978.  are some of the changes that are commonly made to model:
  979.  
  980.  
  981.    ■   Adding user datatypes, rules, or defaults.
  982.  
  983.    ■   Adding to model..sysusers users who are to be given access to all
  984.        databases on SQL Server.
  985.  
  986.    ■   Establishing default permissions, particularly for guest accounts.
  987.  
  988.    ■   Setting database options. The setting of options is then reflected in
  989.        all new databases. The original value of database options in model is
  990.        OFF. Database options are described in Chapter 9, "Fine-tuning
  991.        Performance and Operations."
  992.  
  993.  
  994.  Typically, most users are not granted permission to modify the model
  995.  database. There is no need to grant permission to read it either, since its
  996.  entire contents are copied into each new user database.
  997.  
  998.  
  999.  The tempdb Database
  1000.  
  1001.  The tempdb temporary database provides storage for temporary tables and
  1002.  other temporary storage needs (for example, intermediate results of GROUP BY
  1003.  and ORDER BY).
  1004.  
  1005.  All temporary tables are stored in the temporary database, no matter what
  1006.  database the user who creates them is using. However, you can query a
  1007.  temporary table from inside the database in which it was created or from
  1008.  tempdb. If you query tempdb..sysobjects, you will notice that a suffix is
  1009.  attached to the names of temporary tables. System procedures (for example,
  1010.  sp_help) do not work on temporary tables.
  1011.  
  1012.  The temporary database is a shared work space used by all the databases on
  1013.  SQL Server. Its contents are destroyed every time the current user leaves
  1014.  SQL Server or when the system stops. Temporary objects can also be deleted
  1015.  before a session ends.
  1016.  
  1017.  The default size of the temporary database can be changed by the SA with the
  1018.  ALTER DATABASE statement.
  1019.  
  1020.  No special permissions are required to use the temporary database─that is,
  1021.  to create temporary objects or to execute statements (such as ORDER BY) that
  1022.  may require storage space in the temporary database.
  1023.  
  1024.  
  1025.  The pubs Sample Database
  1026.  
  1027.  Installing the pubs sample database is optional. It is provided as a
  1028.  learning tool and is used as the basis of most of the examples in the SQL
  1029.  Server manual set. The pubs database is illustrated in Appendix A of this
  1030.  guide.
  1031.  
  1032.  The pubs database consists of eight tables: publishers, authors, titles,
  1033.  titleauthor, roysched, sales, stores, and discounts. These tables have the
  1034.  following description:
  1035.  
  1036. ╓┌─────────────────────────────────┌─────────────────────────────────────────╖
  1037.  Table                             Description
  1038.  ────────────────────────────────────────────────────────────────────────────
  1039.  publishers                        Contains the identification numbers,
  1040.                                    names, cities, and states of three
  1041.                                    publishing companies.
  1042.  
  1043.  authors                           Contains an identification number, first
  1044.                                    and last name, address, and contract
  1045.                                    status for each author.
  1046.  
  1047.  titles                            Contains the identification number, name,
  1048.                                    type, publisher identification number,
  1049.                                    price, advance, royalty, year-to-date
  1050.                                    sales, comments, and publication date
  1051.                                    for each book that has been or is about
  1052.  Table                             Description
  1053.  ────────────────────────────────────────────────────────────────────────────
  1054.                                   for each book that has been or is about
  1055.                                    to be published.
  1056.  
  1057.  titleauthor                       Links the titles and authors tables
  1058.                                    together. For each book, it contains the
  1059.                                    title ID, the author ID, the author
  1060.                                    order, and the royalty split among the
  1061.                                    authors of a book.
  1062.  
  1063.  roysched                          Lists the unit sales ranges and the
  1064.                                    royalty connected with each range. The
  1065.                                    royalty is some percentage of the net
  1066.                                    receipts from sales.
  1067.  
  1068.  sales                             Records bookstore sales of titles in the
  1069.                                    titles table.
  1070.  
  1071.  stores                            Lists bookstores by store ID.
  1072.  
  1073.  Table                             Description
  1074.  ────────────────────────────────────────────────────────────────────────────
  1075. 
  1076.  discounts                         Lists three types of discounts for
  1077.                                    bookstores.
  1078.  
  1079.  ────────────────────────────────────────────────────────────────────────────
  1080.  
  1081.  
  1082.  
  1083.  The pubs database contains a guest user mechanism that allows any authorized
  1084.  SQL Server user to access it. The guest user has been given a fairly wide
  1085.  range of permissions in pubs, including permission to select, insert,
  1086.  update, and delete all the user tables. For more on the guest user mechanism
  1087.  and a list of the guest permissions in pubs, see Chapter 6, "Managing User
  1088.  Accounts."
  1089.  
  1090.  
  1091.  
  1092.  
  1093.  
  1094.  
  1095.  Chapter 2  Using the SAF
  1096.  ────────────────────────────────────────────────────────────────────────────
  1097.  
  1098.  
  1099.  Introduction
  1100.  
  1101.  This chapter explains how to use the SQL Server Administration Facility
  1102.  (SAF). The SAF is a system of menus and dialog boxes that allows you to
  1103.  query an SQL database, view the results of your query, and manage your query
  1104.  and results files.
  1105.  
  1106.  
  1107.  Starting the SAF
  1108.  
  1109.  Before you can start the SAF, you need the following information (if
  1110.  necessary, see your SA):
  1111.  
  1112.  
  1113.    ■   The name of the server to which you will log in
  1114.  
  1115.    ■   Your login ID
  1116.  
  1117.    ■   Your password
  1118.  
  1119.  
  1120.  Before you start SAF, you must start your network workstation, if it is not
  1121.  already started.
  1122.  
  1123.  When you start SAF, you can include the server name, username, and password
  1124.  on the command line. You can also omit one or more of the parameters and let
  1125.  SAF prompt you for their values. The following examples show all of the
  1126.  correct ways to start the SAF:
  1127.  
  1128.    saf servername username password
  1129.  
  1130.     saf servername username
  1131.  
  1132.     saf servername
  1133.  
  1134.     saf
  1135.  
  1136.  SAF passes the username and password to the server exactly as you have typed
  1137.  them. If the requested server is case-sensitive, your parameters must match
  1138.  exactly.
  1139.  
  1140.  If you type in parameters, remember that they are position dependent; you
  1141.  must specify them in order. For example, you cannot leave out the server
  1142.  name and type the username and password. This example is incorrect:
  1143.  
  1144.    saf username password
  1145.  
  1146.  Follow these steps in order to start the SAF:
  1147.  
  1148.  
  1149.    1.  Start your network workstation, if it is not already started.
  1150.  
  1151.    2.  Type one of the correct commands as shown above.
  1152.  
  1153.        An introductory dialog box appears on your screen:
  1154.  
  1155.        (This figure may be found in the printed book.)
  1156.  
  1157.    3.  Press the ENTER key.
  1158.  
  1159.        If you did not specify a server name on the command line, skip down to
  1160.        step 9. If you did specify a server name, SAF displays the following
  1161.        message on the bottom of the screen:
  1162.  
  1163.        Attempting to logon...
  1164.  
  1165.    4.  If the parameters you typed were valid and, if the server is running,
  1166.        SAF displays the following message:
  1167.  
  1168.        Connection complete. Inialization in process...
  1169.  
  1170.  
  1171.        After a few moments, SAF displays the  SQL Query Window illustrated in
  1172.        Figure 2-5. This finishes the login sequence.
  1173.  
  1174.    5.  If SAF cannot connect to the server you specified on the command line,
  1175.        it displays the following dialog box (under MS OS/2 only because you
  1176.        cannot start a server from SAF under MS-DOS):
  1177.  
  1178.        (This figure may be found in the printed book.)
  1179.  
  1180.        If you choose Cancel, SAF skips down to step 9 in this login sequence.
  1181.  
  1182.    6.  If you press the  ENTER key, SAF displays the following message on
  1183.        your screen:
  1184.  
  1185.        Attempting to start SQL Server...
  1186.  
  1187.  
  1188.    7.  If it cannot start the server, SAF displays the following dialog box
  1189.        on your screen:
  1190.  
  1191.        (This figure may be found in the printed book.)
  1192.  
  1193.    8.  Press the ENTER key to clear the dialog box.
  1194.  
  1195.    9.  If you do not enter a server name on the command line or, if it cannot
  1196.        locate or start the server you requested, SAF displays the following
  1197.        message on your screen:
  1198.  
  1199.        Please wait for a list of available SQL Servers...
  1200.  
  1201.  
  1202.       After a brief pause, SAF displays the "Login to SQL Server" dialog box
  1203.       on your screen:
  1204.  
  1205.       (This figure may be found in the printed book.)
  1206.  
  1207.       In the center of the dialog box is a list of visible servers to which
  1208.       you can log in. The default server is highlighted.
  1209.  
  1210.    10. To select a server other than the default, use the direction keys to
  1211.        highlight a different server, or press the SHIFT+TAB keys to move to
  1212.        the text box and type in a server name.
  1213.  
  1214.    11. Press the TAB key to move the cursor to the "Login ID" text box.
  1215.  
  1216.    12. If you included a login ID on the SAF command line, SAF displays it in
  1217.        the highlighted text box. Otherwise, type in your login ID.
  1218.  
  1219.    13. Press the TAB key to move to the "Password" text box.
  1220.  
  1221.    14. If you included a password on the SAF command line, SAF places it in
  1222.        the highlighted text box. Otherwise, type in your password. (In either
  1223.        case, your password does not appear on the screen.)
  1224.  
  1225.    15. Press the ENTER key.
  1226.  
  1227.       The SQL Query Window appears on your screen:
  1228.  
  1229.       (This figure may be found in the printed book.)
  1230.  
  1231.       If you type the wrong login ID or password, the following dialog box
  1232.       appears:
  1233.  
  1234.       (This figure may be found in the printed book.)
  1235.  
  1236.       To correct your login ID or password:
  1237.  
  1238.    16. Press the ENTER key to clear the message.
  1239.  
  1240.       The "Login to SQL Server" dialog box reappears.
  1241.  
  1242.    17. Select the server to which you want to log in and type your correct
  1243.        login ID and password.
  1244.  
  1245.    18. Press the ENTER key.
  1246.  
  1247.  
  1248.  If you have problems logging in, see your SA.
  1249.  
  1250.  
  1251.  Responding to Messages
  1252.  
  1253.  As you use the SAF, you will see messages in dialog boxes. Usually the
  1254.  messages ask you a question and then take some action depending on your
  1255.  response. For example, the following message appears when you want to change
  1256.  servers:
  1257.  
  1258.  (This figure may be found in the printed book.)
  1259.  
  1260.  You can log out of the current SQL Server by pressing the ENTER key to
  1261.  select the highlighted OK command button. If you do not want to log out,
  1262.  press the TAB key so that the Cancel command button is highlighted. Then
  1263.  press the ENTER key. The message is cleared from the screen, and you are
  1264.  still logged in to the SQL Server.
  1265.  
  1266.  
  1267.  Menus and Dialog Boxes
  1268.  
  1269.  While using the SAF, you move through a series of displays, making
  1270.  selections and entering information. You encounter two types of displays:
  1271.  menus and dialog boxes.
  1272.  
  1273.  This section describes how to identify and use menus and dialog boxes. You
  1274.  can work with both a keyboard and a mouse, or with just a keyboard.
  1275.  
  1276.  You can press the ESC key at any time to cancel the current operation and
  1277.  move up one level in the SAF. Pressing the ESC key repeatedly returns you to
  1278.  the top level.
  1279.  
  1280.  
  1281.  Menus and Menu Items
  1282.  
  1283.  The names of all available SAF menus appear at the top of the screen:
  1284.  
  1285. ╓┌─────────────────────────────────┌─────────────────────────────────────────╖
  1286.  Menu                              Purpose
  1287.  ────────────────────────────────────────────────────────────────────────────
  1288.  File                              Transfers the contents of a file to and
  1289.                                    from the current SAF window and prints
  1290.                                    the contents of the current SAF window
  1291.                                    or the results of a query.
  1292.  
  1293.  Config                            Logs you in to a different server.
  1294.                                    Additional items on the Config menu are
  1295.                                    available only to SAs.
  1296.  
  1297.  Admin                             Performs system administration
  1298.                                    functions.
  1299.  
  1300.  Query                             Executes an SQL query or prepares for
  1301.                                    the next query. It also allows you to
  1302.                                    start a query log.
  1303.  
  1304.  Menu                              Purpose
  1305.  ────────────────────────────────────────────────────────────────────────────
  1306. 
  1307.  Window                            Selects a query window for typing
  1308.                                    queries or a results window for viewing
  1309.                                    the results of these queries.
  1310.  
  1311.  Help                              Provides help for system administration
  1312.                                    tasks.
  1313.  
  1314.  ────────────────────────────────────────────────────────────────────────────
  1315.  
  1316.  
  1317.  
  1318.  When you select a menu, the SAF displays a list of menu items. For example,
  1319.  when you select the Query menu, you see the following list of menu items on
  1320.  your screen:
  1321.  
  1322.  (This figure may be found in the printed book.)
  1323.  
  1324.  
  1325.  Permission to Use Menu Items
  1326.  
  1327.  Some menu items are available only to SAs or Database Owners. If you do not
  1328.  have permission to choose a menu item, that menu item appears in gray rather
  1329.  than black letters.
  1330.  
  1331.  
  1332.  Choosing a Menu Item with the Keyboard
  1333.  
  1334.  To see a menu's list of items and to choose a menu item with the keyboard:
  1335.  
  1336.  
  1337.    1.  Clear all dialog boxes from the screen.
  1338.  
  1339.        If there are dialog boxes on your screen, press the ESC key repeatedly
  1340.        until all dialog boxes have disappeared.
  1341.  
  1342.    2.  Press the ALT key, which highlights the first letter of each menu.
  1343.  
  1344.    3.  Press the highlighted letter of the menu you want to use.
  1345.  
  1346.        The menu displays its list of menu items.
  1347.  
  1348.    4.  Press the highlighted letter of the menu item you want. (You can also
  1349.        press the direction keys followed by the ENTER key to select an item
  1350.        from the menu.)
  1351.  
  1352.        A dialog box appears on your screen.
  1353.  
  1354.  
  1355.  
  1356.  Example
  1357.  
  1358.  To open an existing file:
  1359.  
  1360.  
  1361.    1.  Press the ALT key.
  1362.  
  1363.    2.  Press F to select the File menu, which looks like this:
  1364.  
  1365.        (This figure may be found in the printed book.)
  1366.  
  1367.    3.  Press O to choose Open.
  1368.  
  1369.        The "Open File" dialog box appears:
  1370.  
  1371.        (This figure may be found in the printed book.)
  1372.  
  1373.  
  1374.  
  1375.  Selecting a Menu Item with a Mouse
  1376.  
  1377.  To select a menu and choose a menu item with a mouse:
  1378.  
  1379.  
  1380.    1.  Move the mouse pointer to the menu you want to use.
  1381.  
  1382.    2.  Press and release the left mouse button. (This action is called
  1383.        clicking.)
  1384.  
  1385.        The selected menu displays its list of menu items.
  1386.  
  1387.    3.  Move the mouse pointer to the menu item you want, and then click the
  1388.        left mouse button.
  1389.  
  1390.        A dialog box appears on your screen.
  1391.  
  1392.  
  1393.  
  1394.  Accelerator Keys
  1395.  
  1396.  Some commonly used menu items have accelerator keys, which are listed to the
  1397.  right of the menu item. Use these keys to choose a menu item without having
  1398.  to select the menu first. The following accelerator keys are available:
  1399.  
  1400. ╓┌───────┌──────────────────────────┌────────────────────────────────────────╖
  1401.  Menu    Menu Item                  Accelerator Key
  1402.  ────────────────────────────────────────────────────────────────────────────
  1403.  File    Exit                       F3
  1404.  Query   Execute Query              CTRL+E
  1405.  Query   Next Query                 CTRL+N
  1406.  Window  SQL Query                  CTRL+Q
  1407.  Window  SQL Results (half screen)  CTRL+R
  1408.  Window  SQL Results Full           CTRL+F
  1409.  Menu    Menu Item                  Accelerator Key
  1410.  ────────────────────────────────────────────────────────────────────────────
  1411. Window  SQL Results Full           CTRL+F
  1412.  ────────────────────────────────────────────────────────────────────────────
  1413.  
  1414.  
  1415.  
  1416.  Dialog Boxes
  1417.  
  1418.  A dialog box has several different areas where you make selections and enter
  1419.  information. It can contain up to five different areas:
  1420.  
  1421.  
  1422.    ■   Text box
  1423.  
  1424.    ■   List box
  1425.  
  1426.    ■   Option buttons
  1427.  
  1428.    ■   Command buttons
  1429.  
  1430.    ■   Display field
  1431.  
  1432.  
  1433.  For example, the "Open File" dialog box contains four areas: a text box, a
  1434.  display field, two list boxes, and two command buttons:
  1435.  
  1436.  (This figure may be found in the printed book.)
  1437.  
  1438.  Use the TAB key to move between the different areas within a dialog box. To
  1439.  move the cursor to a previous area, use the SHIFT+TAB keys to move backward
  1440.  through the fields.
  1441.  
  1442.  
  1443.  Text Boxes
  1444.  
  1445.  A text box is an area in the dialog box where you enter or change
  1446.  information. Sometimes text boxes appear with information already supplied.
  1447.  This is the default information for that text box. If you want to use the
  1448.  default information, leave the text box as is.
  1449.  
  1450.  
  1451.  Using Text Boxes
  1452.  
  1453.  To supply or change the contents of a text box:
  1454.  
  1455.  
  1456.    1.  Press the TAB key to move the cursor to the different areas in the
  1457.        dialog box. Stop when you reach the text box you want to change.
  1458.  
  1459.        (You can also use the SHIFT+TAB keys.)
  1460.  
  1461.    2.  If necessary, delete information already in the text box by pressing
  1462.        the DEL or BACKSPACE key.
  1463.  
  1464.    3.  Type the desired information in the text box.
  1465.  
  1466.  
  1467.  The following keys help you view or change the contents of the text box:
  1468.  
  1469.  Key        Movement
  1470.  ────────────────────────────────────────────────────────────────────────────
  1471.  HOME       Moves the cursor to the left side of any text in the field
  1472.  END        Moves the cursor to the right side of any text in the field
  1473.  DEL        Deletes the character under the cursor
  1474.  BACKSPACE  Deletes the character to the left of the cursor
  1475.  ────────────────────────────────────────────────────────────────────────────
  1476.  
  1477.  A text box can hold more characters than fit in the actual box on the
  1478.  screen. As you type characters, the text box scrolls horizontally to show
  1479.  what you are typing. The HOME, END, LEFT, and RIGHT keys also cause the text
  1480.  box to scroll as necessary.
  1481.  
  1482.  
  1483.  Using Text Boxes with a Mouse
  1484.  
  1485.  To change the contents of a text box with a mouse:
  1486.  
  1487.  
  1488.    1.  Move the mouse pointer to the text box.
  1489.  
  1490.    2.  Click the left mouse button.
  1491.  
  1492.        A text pointer appears inside the text box.
  1493.  
  1494.    3.  Enter, change, or delete information in the same manner as described
  1495.        in "Using Text Boxes," earlier in this chapter.
  1496.  
  1497.  
  1498.  
  1499.  List Boxes
  1500.  
  1501.  A list box presents a list of items to select from, such as a list of
  1502.  filenames.
  1503.  
  1504.  
  1505.  Using List Boxes
  1506.  
  1507.  To select an item in a list box:
  1508.  
  1509.  
  1510.    1.  Press the TAB key to move the cursor into the list box.
  1511.  
  1512.    2.  To see all entries in the box and select an item, use the following
  1513.        keys:
  1514. ╓┌───────────────────┌───────────────────────────────────────────────────────╖
  1515.  Key                 Movement
  1516.  ────────────────────────────────────────────────────────────────────────────
  1517.  UP                  Up one line
  1518.  DOWN                Down one line
  1519.  PG UP               Up one page
  1520.  PG DN               Down one page
  1521.  HOME                To the top of the list
  1522.  END                 To the bottom of the list
  1523.  ────────────────────────────────────────────────────────────────────────────
  1524.  
  1525.  
  1526.  
  1527.  
  1528.  
  1529.  The items in the list box are arranged alphabetically. You can move to the
  1530.  first item starting with a particular letter by pressing that letter while
  1531.  the cursor is in the list box. The item that is highlighted is your selected
  1532.  item.
  1533.  
  1534.  
  1535.    1.  Press the TAB key to go to the next area.
  1536.  
  1537.  
  1538.  
  1539.  Using List Boxes with a Mouse
  1540.  
  1541.  To view or select from the contents of a list box with a mouse:
  1542.  
  1543.  
  1544.    1.  Move the mouse pointer to the scroll bar at the right of the list box.
  1545.  
  1546.        This scroll bar controls what you see in the list box.
  1547.  
  1548.    2.  Place the mouse pointer over the scroll box in the scroll bar. Press
  1549.        and hold down the left mouse button (this action is known as
  1550.        dragging), and move the scroll box up or down.
  1551.  
  1552.        The following list box from the "Open File" dialog box shows the
  1553.        scroll box and scroll bar:
  1554.  
  1555.        (This figure may be found in the printed book.)
  1556.  
  1557.    3.  Drag the scroll box to a location in the scroll bar that roughly
  1558.        corresponds to the location in the list box that you want to bring
  1559.        into view.
  1560.  
  1561.    4.  Release the left mouse button.
  1562.  
  1563.        The view in the list box changes.
  1564.  
  1565.    5.  Move the contents of the list box up or down one line by clicking the
  1566.        up or down arrows at the ends of the scroll bar.
  1567.  
  1568.    6.  Move the mouse pointer to your selection in the list box, and click
  1569.        the left mouse button.
  1570.  
  1571.        The contents of the text box is updated to correspond to your list box
  1572.        selection.
  1573.  
  1574.  
  1575.  
  1576.  Option Buttons
  1577.  
  1578.  An option button is an option preceded by parentheses in a dialog box.
  1579.  Option buttons always appear in sets of at least two; only one option button
  1580.  in a set can be selected at a time. The selected option button has a small
  1581.  circle inside the parentheses.
  1582.  
  1583.  When a dialog box appears on your screen, one option button is highlighted.
  1584.  This is the default option button.
  1585.  
  1586.  
  1587.  Using Option Buttons
  1588.  
  1589.  To select among option buttons:
  1590.  
  1591.  
  1592.    1.  Press the TAB key to move the cursor to the set of option buttons.
  1593.  
  1594.    2.  Use the direction keys to move the cursor between the buttons.
  1595.  
  1596.        When you select a button, a circle appears inside the parentheses.
  1597.  
  1598.  
  1599.  
  1600.  Selecting an Option Button with a Mouse
  1601.  
  1602.  To select an option button with a mouse:
  1603.  
  1604.  
  1605.    1.  Place the mouse pointer on the option button.
  1606.  
  1607.    2.  Click the left mouse button.
  1608.  
  1609.        A circle appears inside the parentheses.
  1610.  
  1611.  
  1612.  
  1613.  Command Buttons
  1614.  
  1615.  Command buttons appear at the bottom of a dialog box as angle brackets with
  1616.  commands in them. These buttons perform an action, such as taking you to
  1617.  another dialog box.
  1618.  
  1619.  When a dialog box appears on your screen, it already has one command button
  1620.  highlighted. This is the default command button.
  1621.  
  1622.  ────────────────────────────────────────────────────────────────────────────
  1623.  NOTE
  1624.  To choose the default command button, press the ENTER key at any time while
  1625.  the dialog box is displayed. You do not have to move the cursor to the
  1626.  default command button before pressing the ENTER key.
  1627.  ────────────────────────────────────────────────────────────────────────────
  1628.  
  1629.  The OK command button tells SAF that you want the actions specified in the
  1630.  dialog box to take effect. This button often appears with the Cancel command
  1631.  button. The Cancel command button exits a dialog box without saving any
  1632.  changes made or executing any actions specified. You can also press the ESC
  1633.  key to exit a dialog box without saving changes or executing actions.
  1634.  
  1635.  
  1636.  Using Command Buttons
  1637.  
  1638.  To choose a command button:
  1639.  
  1640.  
  1641.    1.  Press the TAB key to move the cursor to a command button.
  1642.  
  1643.        The angle brackets around the button are highlighted.
  1644.  
  1645.    2.  Press the ENTER key.
  1646.  
  1647.        The associated action occurs.
  1648.  
  1649.  
  1650.  
  1651.  Using Command Buttons with a Mouse
  1652.  
  1653.  To choose a command button with a mouse:
  1654.  
  1655.  
  1656.    1.  Move the mouse pointer to the command button.
  1657.  
  1658.    2.  Click the left mouse button.
  1659.  
  1660.        The associated action occurs.
  1661.  
  1662.  
  1663.  
  1664.  Display Fields
  1665.  
  1666.  A display field displays information. You cannot modify the contents of a
  1667.  display field.
  1668.  
  1669.  You can distinguish a display field from other areas in the dialog box
  1670.  because the cursor will not move to a display field when you press the TAB
  1671.  key.
  1672.  
  1673.  
  1674.  Getting Help
  1675.  
  1676.  Help on keyboard movement and on complicated administrative procedures is
  1677.  available in the SAF.
  1678.  
  1679.  To get help on the keyboard:
  1680.  
  1681.  
  1682.    1.  Press the ALT+H keys to select the Help menu.
  1683.  
  1684.    2.  Press K to choose Keyboard.
  1685.  
  1686.        A list of keys with their descriptions appears.
  1687.  
  1688.    3.  To exit the "Keyboard" screen, choose Done.
  1689.  
  1690.  
  1691.  To get help on system administration tasks:
  1692.  
  1693.  
  1694.    1.  Press the ALT+H keys to select the Help menu.
  1695.  
  1696.    2.  Press C to choose Contents.
  1697.  
  1698.        A "Contents" screen appears. This screen lists all the system
  1699.        administration topics on which help is available.
  1700.  
  1701.    3.  Select the topic on which you want information.
  1702.  
  1703.    4.  Press ENTER to choose the topic.
  1704.  
  1705.        A screenful of information appears. Use the PG DN key to continue
  1706.        reading about the topic.
  1707.  
  1708.    5.  When you have finished reading about the topic, choose Done.
  1709.  
  1710.  
  1711.  
  1712.  Exiting the SAF
  1713.  
  1714.  To exit the SAF:
  1715.  
  1716.  
  1717.    1.  Clear any dialog boxes on the screen by pressing the ESC key.
  1718.  
  1719.    2.  Press the F3 key.
  1720.  
  1721.        The following dialog box appears:
  1722.  
  1723.        (This figure may be found in the printed book.)
  1724.  
  1725.        Press ENTER to exit from the SAF.
  1726.  
  1727.  
  1728.  You can also exit the SAF from the File menu:
  1729.  
  1730.  
  1731.    1.  Press the ALT+F keys to select the File menu.
  1732.  
  1733.    2.  Press X to choose Exit.
  1734.  
  1735.        The exit dialog box shown in Figure 2.13 is displayed.
  1736.  
  1737.    3.  Press ENTER to exit from the SAF.
  1738.  
  1739.        The SAF screen disappears, and you are back at the operating system
  1740.        prompt.
  1741.  
  1742.  
  1743.  
  1744.  
  1745.  
  1746.  
  1747.  
  1748.  Chapter 3  Making Queries with the SAF
  1749.  ────────────────────────────────────────────────────────────────────────────
  1750.  
  1751.  
  1752.  Introduction
  1753.  
  1754.  This chapter teaches you to use the SAF to make SQL queries and to view the
  1755.  results of these queries. Use this chapter as preparation for SQL Server
  1756.  Learning TRANSACT-SQL, which describes SQL queries in detail and provides
  1757.  many examples for you to try. This chapter does not explain the intricacies
  1758.  of developing SQL queries; instead, it shows you how to use the SAF menus to
  1759.  
  1760.  
  1761.  
  1762.    ■   Create SQL queries
  1763.  
  1764.    ■   Execute queries
  1765.  
  1766.    ■   View the results of queries
  1767.  
  1768.    ■   Modify existing queries
  1769.  
  1770.    ■   Print queries and results
  1771.  
  1772.  
  1773.  This chapter also teaches you how to use the SAF to
  1774.  
  1775.  
  1776.    ■   Create a query log
  1777.  
  1778.    ■   Log in to another server
  1779.  
  1780.  
  1781.  This chapter describes only the SAF functions that are available to all
  1782.  users.
  1783.  
  1784.  
  1785.  About the Examples
  1786.  
  1787.  The pubs sample database, used throughout this manual, includes eight
  1788.  tables. One of these tables, the publishers table, is used for all examples
  1789.  in this chapter. Table 3.1 shows the publishers table.
  1790.  
  1791.  Table 3.1  Publishers Table
  1792.  
  1793.  pub_id  pub_name              city        state
  1794.  ────────────────────────────────────────────────────────────────────────────
  1795.  1389    Algodata Infosystems  Berkeley    CA
  1796.  0736    New Age Books         Boston      MA
  1797.  9877    Binnet & Harley       Washington  DC
  1798.  ────────────────────────────────────────────────────────────────────────────
  1799.  
  1800.  This table contains four columns:
  1801.  
  1802.  Column Name              Description
  1803.  ────────────────────────────────────────────────────────────────────────────
  1804.  pub_id                   Publisher's ID number
  1805.  pub_name                 Publisher's name
  1806.  city                     Publisher's city
  1807.  state                    Publisher's state
  1808.  ────────────────────────────────────────────────────────────────────────────
  1809.  
  1810.  
  1811.  Queries and Results
  1812.  
  1813.  This section contains a brief introduction to SQL queries. Its purpose is to
  1814.  get you familiar with the SAF using some very simple examples. As you learn
  1815.  more about SQL queries in SQL Server Learning TRANSACT-SQL, you will use the
  1816.  SAF extensively.
  1817.  
  1818.  
  1819.  Queries
  1820.  
  1821.  A query includes one or more SQL statements. These statements identify the
  1822.  data to be retrieved from an SQL Server database. After a query is executed,
  1823.  this data is retrieved from the database and returned to your workstation.
  1824.  
  1825.  Use the SELECT statement to make queries. The SELECT statement has the
  1826.  following syntax:
  1827.  
  1828.    SELECT select_list FROM table_list
  1829.  
  1830.  where
  1831.  
  1832.  
  1833.    ■   select_list includes the names of columns from which data is selected.
  1834.        In the publishers table, the column names are pub_id, pub_name, city,
  1835.        and state.
  1836.  
  1837.    ■   table_list includes one or more table names. The examples in this
  1838.        chapter select data from only one table─the publishers table.
  1839.  
  1840.  
  1841.  For example, to query the pubs database to find publishers' IDs and names,
  1842.  the SELECT statement looks like this:
  1843.  
  1844.    select pub_id, pub_name
  1845.     from publishers
  1846.  
  1847.  Note that the statement can be typed on one line or broken into multiple
  1848.  lines. The examples in this manual use multiple lines for readability.
  1849.  
  1850.  
  1851.  Results
  1852.  
  1853.  Results include the data you receive after you execute your query. The
  1854.  results from your queries are presented in table form. The results from the
  1855.  previous query are as follows:
  1856.  
  1857.    pub_id  pub_name
  1858.     ------  --------------------------
  1859.     0736  New Age Books
  1860.     0877  Binnet & Hardley
  1861.     1389  Algodata Infosystems
  1862.  
  1863.  
  1864.  The Window Menu
  1865.  
  1866.  You will use the Window menu frequently as you create queries and look at
  1867.  results. The following three windows are available through the Window menu:
  1868.  
  1869.  
  1870.  
  1871.    ■   SQL Query
  1872.  
  1873.    ■   SQL Results
  1874.  
  1875.    ■   SQL Results Full
  1876.  
  1877.  
  1878.  Only one of these windows is "active" at a time. The active window has a
  1879.  cursor in it. You shift back and forth between these windows frequently as
  1880.  you develop queries and look at results. While using the SAF, you should
  1881.  know which window is active because only the active window can be edited,
  1882.  saved to a file, or printed.
  1883.  
  1884.  
  1885.  Creating Queries
  1886.  
  1887.  This section describes how to create queries using the SQL Query Window.
  1888.  
  1889.  
  1890.  Entering Queries
  1891.  
  1892.  After you log in to SQL Server through the SAF, the SQL Query Window is the
  1893.  first screen to appear. You can then start typing in your query. To correct
  1894.  typing mistakes, use these keys:
  1895.  
  1896.  Key                               Purpose
  1897.  ────────────────────────────────────────────────────────────────────────────
  1898.  BACKSPACE                         Deletes the character to the left of the
  1899.                                    cursor.
  1900.  
  1901.  DEL                               Deletes the character above the cursor.
  1902.  
  1903.  CTRL+O                            Switches between insert mode, where
  1904.                                    characters are added as they are typed,
  1905.                                    and overtype mode, where new characters
  1906.                                    replace existing characters.
  1907.  
  1908.  ────────────────────────────────────────────────────────────────────────────
  1909.  
  1910.  
  1911.  As a sample, try typing this query:
  1912.  
  1913.  (This figure may be found in the printed book.)
  1914.  
  1915.  
  1916.  Scrolling
  1917.  
  1918.  Scrolling is the process of moving text through the window. To scroll
  1919.  through text, use these keys:
  1920.  
  1921. ╓┌─────────────────────┌─────────────────────────────────────────────────────╖
  1922.  Key                   Movement
  1923.  ────────────────────────────────────────────────────────────────────────────
  1924.  PG UP                 Up one screen
  1925.  PG DN                 Down one screen
  1926.  CTRL+HOME             To the top of the screen
  1927.  CTRL+END              To the bottom of the screen
  1928.  HOME                  To the beginning of the line
  1929.  END                   To the end of the line
  1930.  ────────────────────────────────────────────────────────────────────────────
  1931.  
  1932.  
  1933.  
  1934.  Scrolling with a Mouse
  1935.  
  1936.  The SQL windows contain vertical and horizontal scroll bars and scroll
  1937.  boxes:
  1938.  
  1939.  (This figure may be found in the printed book.)
  1940.  
  1941.  To scroll through text with a mouse:
  1942.  
  1943.  
  1944.    1.  Move the mouse pointer to the scroll bar.
  1945.  
  1946.        This scroll bar controls what you see in the window.
  1947.  
  1948.    2.  Place the mouse pointer over the scroll box in the scroll bar. The
  1949.        scroll box represents your current location in the window. Drag the
  1950.        scroll box up or down the vertical scroll bar, or left or right in the
  1951.        horizontal scroll bar.
  1952.  
  1953.    3.  Drag the scroll box to a location in the scroll bar that roughly
  1954.        corresponds to the location in the window that you want to bring into
  1955.        view.
  1956.  
  1957.    4.  Release the left mouse button.
  1958.  
  1959.        The view in the window changes.
  1960.  
  1961.  
  1962.  
  1963.  Selecting and Deleting Text
  1964.  
  1965.  Selecting text is the process of highlighting text for use in editing
  1966.  commands. You can select characters, words, or lines.
  1967.  
  1968.  To select text:
  1969.  
  1970.  
  1971.    1.  Use the direction keys to move to the text you want to select.
  1972.  
  1973.    2.  Press the appropriate keys to select the amount of text you want:
  1974. ╓┌────────────────────────────────┌──────────────────────────────────────────╖
  1975.  Key                              Selection
  1976.  Key                              Selection
  1977.  ────────────────────────────────────────────────────────────────────────────
  1978.  SHIFT+LEFT direction key         Character to the left of the cursor
  1979.  SHIFT+RIGHT direction key        Character to the right of the cursor
  1980.  SHIFT+CTRL+LEFT direction key    Word to the left of the cursor
  1981.  SHIFT+CTRL+RIGHT direction key   Word to the right of the cursor
  1982.  SHIFT+UP direction key           Previous line
  1983.  SHIFT+DOWN direction key         Next line
  1984.  ────────────────────────────────────────────────────────────────────────────
  1985.  
  1986.  
  1987.  
  1988.  
  1989.  
  1990.  For example, you selected pub_id, pub_name, and city from the publishers
  1991.  table:
  1992.  
  1993.    select pub_id, pub_name, city
  1994.     from publishers
  1995.  
  1996.  To select only city and delete pub_id and pub_name from this query:
  1997.  
  1998.  
  1999.    1.  Move the cursor to the first letter in pub_id.
  2000.  
  2001.    2.  Press and hold down the SHIFT key. Press the RIGHT direction key until
  2002.        pub_id, pub_name is highlighted as follows:
  2003.  
  2004.        (This figure may be found in the printed book.)
  2005.  
  2006.    3.  Press the DEL key.
  2007.  
  2008.  
  2009.  If no text is selected, the DEL key deletes the current character. To delete
  2010.  a line of text, move the cursor to the line to be deleted and press CTRL+D.
  2011.  
  2012.  
  2013.  
  2014.  Selecting Text with the Mouse
  2015.  
  2016.  To select text with the mouse, point to the starting place for the selection
  2017.  and click the left mouse button. Drag the mouse pointer to the end of the
  2018.  text you want to select. Release the left mouse button.
  2019.  
  2020.  
  2021.  Executing Queries
  2022.  
  2023.  Once you have created a query and made typing corrections, you are ready to
  2024.  execute the query. When you execute your query, it is sent to the database,
  2025.  and you receive results from the database.
  2026.  
  2027.  To execute your query, from the Query menu, choose Execute query or press
  2028.  CTRL+E.
  2029.  
  2030.  
  2031.  Viewing the Results of Queries
  2032.  
  2033.  After executing your query, the results are displayed on the bottom half of
  2034.  your screen. The query and results look like this:
  2035.  
  2036.  (This figure may be found in the printed book.)
  2037.  
  2038.  
  2039.  Viewing the Query and Results on Separate Screens
  2040.  
  2041.  To view a full screen of results, choose SQL results full from the Window
  2042.  menu or press CTRL+F. The SQL Results Full Window occupies the full screen
  2043.  as follows:
  2044.  
  2045.  (This figure may be found in the printed book.)
  2046.  
  2047.  
  2048.  Scrolling the Results Window
  2049.  
  2050.  Both the SQL Results Window and the SQL Results Full Window are scrollable:
  2051.  they allow you to see all of the data returned by SQL Server, no matter how
  2052.  large that data is. If the results of your query are wider than the screen,
  2053.  you can scroll horizontally to view all of the text in the returned columns.
  2054.  If the results are longer than your screen, you can scroll vertically to
  2055.  view all of the text in the returned rows.
  2056.  
  2057.  It is possible for the results of your query to contain more rows than will
  2058.  fit within the available memory on your workstation. In this case, use the
  2059.  DOWN or PG DN keys to move to the last row retrieved. This moves you to the
  2060.  end of the data that fits in memory. From this point on, every time you
  2061.  press DOWN (or PG DN), the SAF reads another row (or screenful) of results
  2062.  from the SQL Server. For each 20 rows you read, SAF discards 20 rows from
  2063.  the top of the results. These rows are lost; you must reexecute the query to
  2064.  recover them. You can continue scrolling down through the results until you
  2065.  have viewed all of the remaining rows. Pressing CTRL+END causes the SAF to
  2066.  retrieve all remaining rows, discarding rows from the top as necessary.
  2067.  
  2068.  If you move the cursor out of the SQL Results Window before you have viewed
  2069.  all of the results, the SAF discards all of the unread rows. Again, you must
  2070.  reexecute the query to view the discarded rows.
  2071.  
  2072.  
  2073.  Alternating between Different Windows
  2074.  
  2075.  There are several different ways to switch back and forth among the SQL
  2076.  Query, SQL Results, and SQL Results Full windows:
  2077.  
  2078.  
  2079.    ■   Using the Window menu
  2080.  
  2081.    ■   Using the accelerator keys
  2082.  
  2083.    ■   Using the F6 key
  2084.  
  2085.    ■   Using the mouse
  2086.  
  2087.  
  2088.  
  2089.  Accelerator Keys
  2090.  
  2091.  To move from one window to another, use the following accelerator keys:
  2092.  
  2093.  Key                               Action
  2094.  ────────────────────────────────────────────────────────────────────────────
  2095.  CTRL+Q                            Displays the SQL Query Window
  2096.  
  2097.  CTRL+R                            Displays the SQL Results Window (half
  2098.                                    query and half results)
  2099.  
  2100.  CTRL+F                            Displays the SQL Results Full Window
  2101.  
  2102.  CTRL+W                            Shifts back and forth between the two
  2103.                                    halves of the SQL Results Window
  2104.  
  2105.  ────────────────────────────────────────────────────────────────────────────
  2106.  
  2107.  
  2108.  
  2109.  F6 Function Key
  2110.  
  2111.  The easiest way to alternate between the SQL Query, SQL Results, and SQL
  2112.  Results Full windows is to use the F6 function key. This key moves from one
  2113.  window to the next in the following order:
  2114.  
  2115.  (This figure may be found in the printed book.)
  2116.  
  2117.  
  2118.  Modifying Previous Queries and Results
  2119.  
  2120.  After making a query, you will often want to make changes to the query or
  2121.  results. If you have not cleared the windows, you can modify the query or
  2122.  results. To change the query or results:
  2123.  
  2124.  
  2125.    1.  For a query, make the SQL Query Window the active window. For results,
  2126.        make the SQL Results Window the active window.
  2127.  
  2128.        (You can select either the SQL Results Window or the SQL Results Full
  2129.        Window.)
  2130.  
  2131.    2.  Make editing changes.
  2132.  
  2133.  
  2134.  
  2135.  Making a New Query
  2136.  
  2137.  To clear the SQL Query and SQL Results windows and make a new query:
  2138.  
  2139.  
  2140.    1.  From the Query menu, choose Next query or press CTRL+N.
  2141.  
  2142.        The SQL Query Window appears.
  2143.  
  2144.    2.  Start typing your new query. (See "Creating Queries," earlier in this
  2145.        chapter, for details).
  2146.  
  2147.  
  2148.  
  2149.  Saving Queries and Results
  2150.  
  2151.  You may want to save a query or its results in a file. Once you've saved a
  2152.  query to a file, you can rerun it easily using the SAF.
  2153.  
  2154.  
  2155.  Filenames for Query and Results Files
  2156.  
  2157.  Although not required, it is convenient to use the following filename
  2158.  extensions for your query and results files:
  2159.  
  2160.  Extension  Type of File  Example
  2161.  ────────────────────────────────────────────────────────────────────────────
  2162.  QRY        Query         PUBDATA.QRY
  2163.  RES        Results       ADDRESS.RES
  2164.  
  2165.  ────────────────────────────────────────────────────────────────────────────
  2166.  
  2167.  
  2168.  Using these extensions is helpful when you retrieve one of the files using
  2169.  the "Open Filename" dialog box.
  2170.  
  2171.  
  2172.  Saving Queries or Results to a File
  2173.  
  2174.  To save a query or results to a file:
  2175.  
  2176.  
  2177.    1.  For a query, make the SQL Query Window the active window. For results,
  2178.        make the SQL Results Window the active window.
  2179.  
  2180.    2.  From the File menu, choose Save as.
  2181.  
  2182.        A dialog box appears:
  2183.  
  2184.        (This figure may be found in the printed book.)
  2185.  
  2186.    3.  Type the filename in the text box.
  2187.  
  2188.        You can type either a complete pathname or a filename only. (If you
  2189.        type a filename only, your file is saved in the current directory.)
  2190.        Notice that the complete pathname of the saved query file replaces the
  2191.        word "untitled" in the screen header.
  2192.  
  2193.        (This figure may be found in the printed book.)
  2194.  
  2195.  ────────────────────────────────────────────────────────────────────────────
  2196.  NOTE
  2197.  
  2198.  The SAF imposes a 511 line limit on input query files. You can save a query
  2199.  with more than 511 lines to a file, but you cannot execute it from the
  2200.  SAF.─────────────────────────────────────────────────────────────────────────
  2201.  
  2202.  
  2203.  
  2204.  
  2205.  Working with Saved Queries and Results
  2206.  
  2207.  To open a saved query or results file:
  2208.  
  2209.  
  2210.    1.  For a query, make the SQL Query Window the active window. For results,
  2211.        make the SQL Results Window the active window.
  2212.  
  2213.        NOTE  When you open a file, the SQL Query and the SQL Results windows
  2214.        are cleared of all text. If you want to save your latest query or
  2215.        results, do so before opening a new file.
  2216.  
  2217.    2.  From the File menu, choose Open.
  2218.  
  2219.        A message appears:
  2220.  
  2221.        OK to clear active window?
  2222.  
  2223.    3.  Choose OK to clear the active window.
  2224.  
  2225.        A dialog box appears:
  2226.  
  2227.        (This figure may be found in the printed book.)
  2228.  
  2229.    4.  Select the file you want to open from the list box, or type the name
  2230.        of the file if it does not appear in the list box.
  2231.  
  2232.        Filenames in the current directory that have an extension of .QRY or
  2233.        .RES are displayed in the "Choose" list box.
  2234.  
  2235.        If the file you want to open is not in the current directory, type the
  2236.        complete pathname or the directory name in the text box. A new list
  2237.        box full of filenames appears.
  2238.  
  2239.    5.  Choose OK.
  2240.  
  2241.        The file you opened appears in the SQL Query or SQL Results window.
  2242.  
  2243.  
  2244.  You can make changes to this file, execute it (if it is a query file), save
  2245.  it, or print it.
  2246.  
  2247.  
  2248.  Printing Queries and Results
  2249.  
  2250.  To print a query or its results:
  2251.  
  2252.  
  2253.    1.  For a query, make the SQL Query Window the active window. For results,
  2254.        make the SQL Results Window the active window.
  2255.  
  2256.    2.  From the File menu, choose Print.
  2257.  
  2258.        A dialog box appears and printing starts:
  2259.  
  2260.        (This figure may be found in the printed book.)
  2261.  
  2262.    3.  To cancel printing, choose Cancel.
  2263.  
  2264.  
  2265.  Your query or results are automatically printed on LPT1. Or you can change
  2266.  the default printer to LPT2, your other option:
  2267.  
  2268.  
  2269.    1.  From the File menu, choose Change printer.
  2270.  
  2271.        A dialog box appears:
  2272.  
  2273.        (This figure may be found in the printed book.)
  2274.  
  2275.    2.  Select "LPT2" from the list box.
  2276.  
  2277.    3.  Choose OK.
  2278.  
  2279.  
  2280.  
  2281.  Logging Queries and Results to a File
  2282.  
  2283.  A query log is a file that stores all your queries and results in
  2284.  chronological order. Each new query or result is added to the end of this
  2285.  file until you choose End query log from the Query menu. The query log is a
  2286.  standard ASCII file and can be accessed with a text editor.
  2287.  
  2288.  To start your log:
  2289.  
  2290.  
  2291.    1.  From the Query menu, choose Begin query log.
  2292.  
  2293.        A dialog box appears:
  2294.  
  2295.        (This figure may be found in the printed book.)
  2296.  
  2297.    2.  Select the file you want to open from the list box, or type the name
  2298.        of the file if it does not appear in the list box.
  2299.  
  2300.        Filenames in the current directory that have an extension of .LOG are
  2301.        displayed in the list box.
  2302.  
  2303.        If the log file is located in another directory, type the name of the
  2304.        directory in the "Open Filename" text box. Once you have typed the
  2305.        name of the directory, the files in the list box will change and you
  2306.        can select a file.
  2307.  
  2308.        (To continue using an existing log file, select the name of the
  2309.        existing file and press ENTER. Your queries and results will then be
  2310.        added to the end of the existing file.)
  2311.  
  2312.    3.  Choose OK.
  2313.  
  2314.  
  2315.  From this point until the time you end logging, the Query menu displays End
  2316.  query log rather than Begin query log.
  2317.  
  2318.  To stop logging:
  2319.  
  2320.  
  2321.    ■   Choose End query log from the Query menu.
  2322.  
  2323.  
  2324.  
  2325.  Logging In to Another Server
  2326.  
  2327.  To log in to a different server:
  2328.  
  2329.  
  2330.    1.  From the Config menu, choose Login.
  2331.  
  2332.        A message appears:
  2333.  
  2334.        (This figure may be found in the printed book.)
  2335.  
  2336.        Before you can log in to a different server, you have to log out of
  2337.        your current server.
  2338.  
  2339.    2.  Choose OK.
  2340.  
  2341.        A dialog box appears:
  2342.  
  2343.        (This figure may be found in the printed book.)
  2344.  
  2345.    3.  Select a server from the list box.
  2346.  
  2347.    4.  Type your login ID and password for this server.
  2348.  
  2349.    5.  Choose OK.
  2350.  
  2351.        You are logged in to the server you specified.
  2352.  
  2353.  
  2354.  
  2355.  
  2356.  
  2357.  
  2358.  
  2359.  Chapter 4  Starting and Shutting Down SQL Server
  2360.  ────────────────────────────────────────────────────────────────────────────
  2361.  
  2362.  
  2363.  Introduction
  2364.  
  2365.  There are several ways to start and to shut down the SQL Server.
  2366.  
  2367.  To start SQL Server, you can use any of the following:
  2368.  
  2369.  
  2370.    ■   The SAF
  2371.  
  2372.    ■   The net command
  2373.  
  2374.    ■   The sqlservr program
  2375.  
  2376.  
  2377.  To shut down SQL Server, you can use any of the following:
  2378.  
  2379.  
  2380.    ■   The SAF Config menu
  2381.  
  2382.    ■   The net command
  2383.  
  2384.    ■   The SHUTDOWN statement
  2385.  
  2386.  
  2387.  The method you use depends on the network software you are running.
  2388.  
  2389.  
  2390.    ■   If your network is a Microsoft LAN Manager for MS OS/2 or an IBM(R)
  2391.        LAN Server, use the SAF or the net command.
  2392.  
  2393.    ■   If you are using a network other than LAN Manager for MS OS/2 or IBM
  2394.        LAN Server, use the sqlservr program or the SHUTDOWN statement.
  2395.  
  2396.  
  2397.  
  2398.  Starting SQL Server
  2399.  
  2400.  This section describes two of the ways to start SQL Server:
  2401.  
  2402.  
  2403.    ■   Using the SAF (MS OS/2 only)
  2404.  
  2405.    ■   Using the net command
  2406.  
  2407.  
  2408.  
  2409.  Starting SQL Server Using the SAF (MS OS/2 Only)
  2410.  
  2411.  To start SQL Server using the SAF (under MS OS/2 only):
  2412.  
  2413.  
  2414.    1.  At the C > prompt, type
  2415.  
  2416.         saf
  2417.  
  2418.  
  2419.        The copyright screen appears.
  2420.  
  2421.    2.  Choose OK.
  2422.  
  2423.        The "Login to SQL Server" dialog box appears.
  2424.  
  2425.    3.  From the "Server names" list box, select the name of the server you
  2426.        want to start. If the server is not visible, it will not appear in the
  2427.        list box. In that case, type it into the text box.
  2428.  
  2429.    4.  Press the TAB key to move the cursor to the "Login ID" text box, and
  2430.        type your login ID.
  2431.  
  2432.    5.  Press the TAB key to move to the "Password" text box, and type your
  2433.        password.
  2434.  
  2435.    6.  Press the ENTER key.
  2436.  
  2437.        The "Start a Server" dialog box appears.
  2438.  
  2439.    7.  Choose OK to start the server.
  2440.  
  2441.  
  2442.  
  2443.  Starting SQL Server Using the net Command
  2444.  
  2445.  To start SQL Server using the net command provided with your network
  2446.  software:
  2447.  
  2448.  
  2449.    1.  At the C > prompt, type
  2450.  
  2451.        net start sqlserver
  2452.  
  2453.  
  2454.    2.  Press the ENTER key.
  2455.  
  2456.  
  2457.  
  2458.  Shutting Down SQL Server
  2459.  
  2460.  This section describes three ways to shut down SQL Server:
  2461.  
  2462.  
  2463.    ■   Using the SAF Config menu
  2464.  
  2465.    ■   Using the SHUTDOWN statement
  2466.  
  2467.    ■   Using the net command.
  2468.  
  2469.  
  2470.  
  2471.  Shutting Down SQL Server Using the Config Menu
  2472.  
  2473.  To shut down SQL Server from the SAF Config menu:
  2474.  
  2475.  
  2476.    1.  Select the Config menu, and choose Shutdown SQL Server.
  2477.  
  2478.        A dialog box appears.
  2479.  
  2480.    2.  Choose OK.
  2481.  
  2482.        SQL Server then waits for currently executing SQL statements or stored
  2483.        procedures to finish, performs a checkpoint in every database, and
  2484.        then shuts down the server to which you are logged in. (You can shut
  2485.        down SQL Server from a workstation.)
  2486.  
  2487.  
  2488.  
  2489.  Shutting Down SQL Server Using the SHUTDOWN Statement
  2490.  
  2491.  To shut down SQL Server with the SHUTDOWN statement:
  2492.  
  2493.  
  2494.    1.  In the SQL Query Window, type
  2495.  
  2496.        shutdown
  2497.  
  2498.  
  2499.    2.  Execute this statement by pressing CTRL+E.
  2500.  
  2501.        SQL Server then waits for currently executing SQL statements or stored
  2502.        procedures to finish, performs a checkpoint in every database, and
  2503.        then shuts down the server to which you are logged in. (You can shut
  2504.        down SQL Server from a workstation.)
  2505.  
  2506.  
  2507.  For more information on the SHUTDOWN statement, see the SQL Server Language
  2508.  Reference.
  2509.  
  2510.  
  2511.  Shutting Down SQL Server Using the net Command
  2512.  
  2513.  To shut down SQL Server immediately, use the net command provided with your
  2514.  network software.
  2515.  
  2516.  ────────────────────────────────────────────────────────────────────────────
  2517.  WARNING
  2518.  
  2519.  Use this command only if you want to shut down SQL Server immediately
  2520.  without waiting for active statements to complete, and without performing
  2521.  checkpoints. Restarting the database will take longer if checkpoints are not
  2522.  performed, although full transaction integrity is guaranteed in either case.
  2523.  ────────────────────────────────────────────────────────────────────────────
  2524.  
  2525.  To use the net command:
  2526.  
  2527.  
  2528.    1.  At the C > prompt, type
  2529.  
  2530.        net stop sqlserver
  2531.  
  2532.  
  2533.    2.  Press the ENTER key.
  2534.  
  2535.  
  2536.  
  2537.  
  2538.  
  2539.  
  2540.  
  2541.  Chapter 5  Managing Storage
  2542.  ────────────────────────────────────────────────────────────────────────────
  2543.  
  2544.  
  2545.  Introduction
  2546.  
  2547.  In SQL Server, you create files in which databases and database backups will
  2548.  be stored. Once these files (called database devices and dump devices) are
  2549.  created, you can then create databases, add data to databases, and back up
  2550.  databases.
  2551.  
  2552.  This chapter describes how to
  2553.  
  2554.  
  2555.    ■   Add database devices and dump devices
  2556.  
  2557.    ■   Create databases and transaction logs
  2558.  
  2559.    ■   Drop databases
  2560.  
  2561.    ■   Drop database devices and dump devices
  2562.  
  2563.  
  2564.  In many organizations, the SA retains complete control over these tasks.
  2565.  
  2566.  
  2567.  Dumping the master Database
  2568.  
  2569.  You should dump the master database at the following times:
  2570.  
  2571.  
  2572.    ■   After you add a database device or a dump device
  2573.  
  2574.    ■   After you create a database and a transaction log
  2575.  
  2576.    ■   After you drop a database
  2577.  
  2578.    ■   After you drop a database device or a dump device
  2579.  
  2580.  
  2581.  
  2582.  Adding Database Devices and Dump Devices
  2583.  
  2584.  Immediately after installation, SQL Server includes one database device and
  2585.  three dump devices. As you create databases on SQL Server, you will need to
  2586.  add and monitor database devices and dump devices. This section describes
  2587.  how to
  2588.  
  2589.  
  2590.    ■   Add database devices
  2591.  
  2592.    ■   Set up a pool of default database devices
  2593.  
  2594.    ■   Add dump devices
  2595.  
  2596.    ■   Display information on database devices and dump devices
  2597.  
  2598.  
  2599.  
  2600.  Database Devices and Dump Devices
  2601.  
  2602.  SQL Server databases and transaction logs are stored in hard disk files
  2603.  called database devices. You cannot create a database until you have created
  2604.  a database device to store that database.
  2605.  
  2606.  Many databases can be contained within a single database device. Also, one
  2607.  database can be stored in several database devices.
  2608.  
  2609.  SQL Server database backups (dumps) can be stored in diskette files or hard
  2610.  disk files. These backup files are called dump devices.
  2611.  
  2612.  Each database device and dump device has two names: a physical name and a
  2613.  logical name. The physical name is the name of the MS OS/2 file. The
  2614.  physical name follows the MS OS/2 rules for filenames and must include a
  2615.  complete pathname.
  2616.  
  2617.  The logical name is a name used by SQL Server for the database device or
  2618.  dump device. When using most SQL statements, you refer to the database
  2619.  device or dump device by its logical name. The logical name follows the SQL
  2620.  Server rules for identifiers. (See the SQL Server Language Reference for
  2621.  these rules.)
  2622.  
  2623.  Examples of physical and logical names are:
  2624.  
  2625.  Type of File     Physical Name            Logical Name
  2626.  ────────────────────────────────────────────────────────────────────────────
  2627.  Database device  c:\sql\data\cust.dat     customer_list
  2628.  Database device  d:\sql\data\reserve.dat  reservations
  2629.  Dump device      a:\sqltable.dat          diskettedumpa
  2630.  Dump device      b:\sqltable.dat          diskettedumpb
  2631.  ────────────────────────────────────────────────────────────────────────────
  2632.  
  2633.  
  2634.  Adding Database Devices
  2635.  
  2636.  You add new database devices with the DISK INIT statement. The DISK INIT
  2637.  statement gives the database device a physical and logical name and prepares
  2638.  the database device for database storage.
  2639.  
  2640.  Before you add a database device with the DISK INIT statement, you must
  2641.  obtain a device number for the database device. You do this by executing the
  2642.  sp_helpdevice system procedure. After executing sp_helpdevice, locate the
  2643.  highest number in the device_number column. Choose the next number as the
  2644.  device number for the database device you are about to create.
  2645.  
  2646.  The DISK INIT statement has the following syntax:
  2647.  
  2648.    DISK INIT
  2649.      NAME = "logical_name" ,
  2650.      PHYSNAME = "physical_name" ,
  2651.      VDEVNO = virtual_device_number ,
  2652.      SIZE = number_of_blocks
  2653.      [, VSTART = virtual_address ,
  2654.      CNTRLTYPE = controller_number ]
  2655.  
  2656.  The following list describes each keyword:
  2657.  
  2658.  ────────────────────────────────────────────────────────────────────────────
  2659.  NAME
  2660.    The logical name of the database device. It is the name used within SQL
  2661.    Server. NAME must follow the rules for identifiers (Although names longer
  2662.    than 30 characters are allowed, the name will be truncated to 30
  2663.    characters.)
  2664.  
  2665.  PHYSNAME
  2666.    The physical name of the database device. PHYSNAME is an MS OS/2 filename
  2667.    that includes a complete path.
  2668.  
  2669.  VDEVNO
  2670.    An identifying number for the database device. It must be unique among
  2671.    database devices and dump devices used by SQL Server. The device number 0
  2672.    is reserved for the master database device. Legal numbers are between 1
  2673.    and 9.
  2674.  
  2675.  SIZE
  2676.    The size of the database device in 2 kilobyte (K) blocks. There are 512 2K
  2677.    blocks in a megabyte.
  2678.  
  2679.    If you are planning to use the new database device for the creation of a
  2680.    new database, the minimum size is the size of model, 1024 2K blocks (2
  2681.    megabytes).
  2682.  
  2683.    If you are adding a database device for a transaction log, SIZE can be as
  2684.    small as  512 2K blocks (1 megabyte).
  2685.  
  2686.  VSTART
  2687.    The starting virtual address, or the offset in 2K blocks, for SQL Server
  2688.    to begin using the database device. The default value (and usually the
  2689.    preferred value) of VSTART is zero.
  2690.  
  2691.  CNTRLTYPE
  2692.    The disk controller. Its default value is zero. Reset it only if
  2693.    instructed to do so.
  2694.  
  2695.  ────────────────────────────────────────────────────────────────────────────
  2696.  The following example shows the DISK INIT statement used to add a database
  2697.  device with a logical name of employees, a physical name of
  2698.  c:\sql\data\mp1.dat, a device number of 8, and a size of 10240K (or 5120 2K
  2699.  blocks). (To find the correct device number, you would execute sp_helpdevice
  2700.  before executing the DISK INIT statement.)
  2701.  
  2702.    disk init
  2703.     name = "employees",
  2704.     physname = "c:\sql\data\mp1.dat",
  2705.     vdevno = 8,
  2706.     size = 5120
  2707.  
  2708.  The DISK INIT statement prepares devices for use by SQL Server. It divides
  2709.  the database devices into allocation units, each of which is 256 2K pages (a
  2710.  total of one-half megabyte). The minimum amount of storage space that can be
  2711.  assigned to a database is the size of the model database, which is four
  2712.  allocation units (2 megabytes).
  2713.  
  2714.  In each allocation unit, the DISK INIT statement initializes the first of
  2715.  the 256 pages as the allocation page, which will contain information about
  2716.  the database (if any) that resides on the allocation unit. The DISK INIT
  2717.  statement also clears all pages.
  2718.  
  2719.  ────────────────────────────────────────────────────────────────────────────
  2720.  WARNING
  2721.  
  2722.  You should dump the master database after you add one or more database
  2723.  devices.
  2724.  ────────────────────────────────────────────────────────────────────────────
  2725.  
  2726.  
  2727.  Setting Up Default Database Devices
  2728.  
  2729.  The SA often sets up a pool of default database devices, which is then
  2730.  available whenever a database is created.
  2731.  
  2732.  To add a database device to (or remove it from) the pool of default database
  2733.  devices, execute the sp_diskdefault system procedure. The sp_diskdefault
  2734.  system procedure has the following syntax:
  2735.  
  2736.    sp_diskdefault "database_device", {defaulton | defaultoff}
  2737.  
  2738.  ────────────────────────────────────────────────────────────────────────────
  2739.  database_device
  2740.    The logical name of the database device. Use the sp_helpdevice system
  2741.    procedure, if necessary, to find the logical name.
  2742.  
  2743.  defaulton, defaultoff
  2744.    Use defaulton if the specified database device is to be designated a
  2745.    default database device. Use defaultoff if the specified database device
  2746.    is not to be designated a default database device. The defaulton option
  2747.    will most frequently be used after a database device has been added to the
  2748.    system with DISK INIT. The defaultoff option will most frequently be used
  2749.    to change the default status of the master database device (which is on
  2750.    when SQL Server is first installed).
  2751.  
  2752.  ────────────────────────────────────────────────────────────────────────────
  2753.  For example, the following example shows the new database device employees
  2754.  added to the pool of default database devices:
  2755.  
  2756.    sp_diskdefault "employees", defaulton
  2757.  
  2758.  The following example shows how to remove the newdb database device from the
  2759.  pool of default database devices:
  2760.  
  2761.    sp_diskdefault "newdb", defaultoff
  2762.  
  2763.  It is a good idea to put a database and its transaction log into separate
  2764.  database devices. (See "Putting the Transaction Log into a Different
  2765.  Database Device," later in this chapter.)
  2766.  
  2767.  
  2768.  Adding Dump Devices
  2769.  
  2770.  To add dump devices other than those already supplied with SQL Server, use
  2771.  the sp_addumpdevice system procedure. This procedure has the following
  2772.  syntax:
  2773.  
  2774.    sp_addumpdevice {"disk" | "diskette"}, "logical_name",
  2775.      "physical_name", cntrltype [, noskip | skip [, media_capacity]]
  2776.  
  2777.  ────────────────────────────────────────────────────────────────────────────
  2778.  "disk","diskette"
  2779.    The type of dump device. Use "disk" for adding a hard disk file as a dump
  2780.    device. Use "diskette" for adding a 5.25 inch or 3.5 inch diskette file as
  2781.    a dump device.
  2782.  
  2783.  logical_name
  2784.    The logical name of the dump device. This name must follow the rules for
  2785.    identifiers. (If you specify a name longer than 30 characters, the name is
  2786.    truncated to 30 characters.)
  2787.  
  2788.  physical_name
  2789.    The physical name of the dump device. This name must follow the rules for
  2790.    MS OS/2 filenames and must include a full pathname.
  2791.  
  2792.  cntrltype
  2793.    The controller number of the new dump device. The same controller number
  2794.    can be used for more than one dump device. For hard disk dump devices, the
  2795.    controller number must be 2. For diskette dump devices, the controller
  2796.    number must be 3 or 4. If there are two diskette dump devices, use
  2797.    controller number 3 for one and controller number 4 for the other.
  2798.  
  2799.  noskip, skip
  2800.    Indicates whether ANSI tape labels are read (noskip) or ignored (skip).
  2801.    Use noskip for diskette dump devices. (The skip option is reserved for
  2802.    future tape support.)
  2803.  
  2804.  media_capacity
  2805.    The storage capacity of the diskette (in megabytes). The default is 1.2
  2806.    megabytes. Use this parameter only for adding a diskette dump device. If
  2807.    you specify media_capacity, you must also specify the noskip option.
  2808.  
  2809.  ────────────────────────────────────────────────────────────────────────────
  2810.  For example, to add a diskette dump device with a capacity of 360K, execute
  2811.  the following statement:
  2812.  
  2813.    sp_addumpdevice "diskette", "diskettedumpb",
  2814.      "b:\sqldump.dat", 4, noskip, .36
  2815.  
  2816.  There are several special logical names for dump devices. The dump device
  2817.  known as diskdump sends dumped data to the null device. Using the name
  2818.  diskdump will dump data without putting it anywhere. Some installations use
  2819.  the diskdump name as a "bit bucket."
  2820.  
  2821.  If you add a dump device with a physical name of null and any logical name,
  2822.  the dump device will be added. However, its physical name will be changed to
  2823.  nul and its logical name will be changed to diskdump.
  2824.  
  2825.  ────────────────────────────────────────────────────────────────────────────
  2826.  WARNING
  2827.  
  2828.  You should dump the master database after you add a dump device.
  2829.  ────────────────────────────────────────────────────────────────────────────
  2830.  
  2831.  
  2832.  Displaying Information on Database Devices and Dump Devices
  2833.  
  2834.  Use the sp_helpdevice system procedure to display information about database
  2835.  devices and dump devices.
  2836.  
  2837.  The following information is displayed when you execute sp_helpdevice:
  2838.  
  2839.    sp_helpdevice
  2840.  
  2841.     device_name   physical_name
  2842.      description
  2843.      status   cntrltype  device_number low  high
  2844.     ---------------  -----------------------------
  2845.      ------------------------------
  2846.      -----------  ------------- ------------- ----- ------
  2847.     diskdump   nul
  2848.      disk dump device
  2849.      16    2    0    0  20000
  2850.     diskettedumpa  a:sqltable.dat
  2851.      diskette, 1.2 Mb, dump device
  2852.      16    3    0    0  19
  2853.     diskettedumpb  b:sqltable.dat
  2854.      diskette, 1.2 Mb, dump device
  2855.      16    4    0    0  19
  2856.     master    c:\sql\data\master.dat
  2857.      special, default disk, physical disk, 10 Mb
  2858.      3    0    0    0  5119
  2859.  
  2860.     (4 rows affected)
  2861.  
  2862.  The report contains the following fields:
  2863.  
  2864.  ────────────────────────────────────────────────────────────────────────────
  2865.  device_name
  2866.    The logical name of a database device or dump device.
  2867.  
  2868.  physical_name
  2869.    The physical name of a database device or dump device.
  2870.  
  2871.  description
  2872.    The type of database device or dump device (disk or diskette).
  2873.  
  2874.  status
  2875.    The type of device:
  2876.  
  2877.    2  Database device
  2878.  
  2879.    3  Default database device
  2880.  
  2881.    16  Dump device (either disk or diskette)
  2882.  
  2883.  cntrltype
  2884.    The controller type:
  2885.  
  2886.    0  Database device
  2887.  
  2888.    2  Disk dump device
  2889.  
  2890.    3-4  Diskette dump device
  2891.  
  2892.  device_number
  2893.    The virtual device number. All database devices and dump devices have a
  2894.    unique number.
  2895.  
  2896.  low
  2897.    The first virtual page number for a database device. For a dump device,
  2898.    the low value is always 0.
  2899.  
  2900.  high
  2901.    The last virtual page number for a database device. For a dump device, the
  2902.    high value equals the media capacity specified when the device was
  2903.    created. The high value shows media capacity in 62K blocks; for example, a
  2904.    value of 19 equals 1.2 megabytes (62K * 19).
  2905.  
  2906.  ────────────────────────────────────────────────────────────────────────────
  2907.  Advanced users may want to query the sysdevices system table for additional
  2908.  information on database devices and dump devices. See Appendix B, "System
  2909.  Tables," for a description of this table.
  2910.  
  2911.  
  2912.  Creating Databases and Transaction Logs
  2913.  
  2914.  After installation, SQL Server includes these databases: master, tempdb, and
  2915.  model. You may also choose to load the example database, pubs.
  2916.  
  2917.  This section describes how to
  2918.  
  2919.  
  2920.    ■   Create a database and transaction log
  2921.  
  2922.    ■   Put a transaction log into a separate database device
  2923.  
  2924.    ■   Expand transaction log space
  2925.  
  2926.    ■   Alter database size
  2927.  
  2928.    ■   Display information on database storage
  2929.  
  2930.  
  2931.  
  2932.  Creating a Database
  2933.  
  2934.  Databases are allocated storage space when the CREATE DATABASE or ALTER
  2935.  DATABASE statement is executed. In most organizations, only the SA executes
  2936.  these statements to prevent inadvertent or unauthorized use of storage
  2937.  space. However, the SA can grant permission for these statements to other
  2938.  users if desired. (The SA can transfer ownership of a database to another
  2939.  user after it is created.)
  2940.  
  2941.  The CREATE DATABASE statement can specify one or more database devices and
  2942.  the amount of space in each that is to be allocated to the new database. If
  2943.  no database device or size is specified (or if the keyword DEFAULT is used),
  2944.  SQL Server puts the database in one or more of the default database devices
  2945.  and assigns it the default size of 2 megabytes. To see which database
  2946.  devices are available, execute the sp_helpdevice system procedure. You
  2947.  should place a database and its transaction log in separate devices. You
  2948.  must do this if the database is larger than 4 megabytes.
  2949.  
  2950.  ────────────────────────────────────────────────────────────────────────────
  2951.  NOTE
  2952.  
  2953.  The allocation decisions that you make when you execute CREATE DATABASE or
  2954.  ALTER DATABASE are important because it is difficult to reclaim storage
  2955.  space once it's assigned. If the database runs out of space, additional
  2956.  space must be allocated.
  2957.  ────────────────────────────────────────────────────────────────────────────
  2958.  
  2959.  The CREATE DATABASE statement can be executed only while using the master
  2960.  database. This statement has the following syntax:
  2961.  
  2962.    CREATE DATABASE database_name
  2963.     [ON {DEFAULT [= size] , database_device [= size]
  2964.      [, database_device [= size]]...}]
  2965.  
  2966.  ────────────────────────────────────────────────────────────────────────────
  2967.  database_name
  2968.    The name of the new database. It must conform to the rules for
  2969.    identifiers.
  2970.  
  2971.  ON
  2972.    Specifies a location and (optionally) a size for the database.
  2973.  
  2974.  DEFAULT
  2975.    Puts the new database in any default database device. To specify a size
  2976.    for the database without specifying a location, use "ON DEFAULT = size".
  2977.  
  2978.  database_device
  2979.    The logical name of the database device into which you want to put the
  2980.    database. A database can occupy different amounts of space in each of
  2981.    several database devices. To see a list of existing logical names, execute
  2982.    sp_helpdevice.
  2983.  
  2984.  size
  2985.    The amount of space allocated to the database (in megabytes). The
  2986.    SQL-Server-supplied default size is 2 megabytes. The SA can change the
  2987.    default size. (See Chapter 9, "Fine-tuning and Performance Operations,"
  2988.    for information.) The default size is usually the same size as the model
  2989.    database and must be at least as large as the model database. The legal
  2990.    values for a database size range from 2 to 223.
  2991.  
  2992.  ────────────────────────────────────────────────────────────────────────────
  2993.  For example, if you want to create a database in default database devices
  2994.  with the default database size, type
  2995.  
  2996.    create database pubs
  2997.  
  2998.  To specify a size (in this example, 4 megabytes) for a database to be stored
  2999.  in a default location, use "ON DEFAULT = size" like this:
  3000.  
  3001.    create database newpubs
  3002.     on default = 4
  3003.  
  3004.  To specify a different location for the database, give the name of the
  3005.  database device in which you want it stored. You can request that a database
  3006.  be stored in more than one database device, with different amounts of space
  3007.  in each. This statement creates the newdb database and allocates to it 3
  3008.  megabytes in the default database device and 2 megabytes in newdata:
  3009.  
  3010.    create database newdb
  3011.     on default = 3, newdata = 2
  3012.  
  3013.  If the ON clause is omitted, the database is created with the default amount
  3014.  of space indicated in master..sysconfigures (usually 2 megabytes) on the
  3015.  default database device indicated in master..sysdevices. A database can
  3016.  range in size from a minimum of  2 megabytes to 223 megabytes.
  3017.  
  3018.  If the amount of space you request in a specific database device is
  3019.  unavailable, SQL Server creates the database with as much space as possible
  3020.  on a per-device basis. It then displays a message informing you how much
  3021.  space was actually allocated in each database device. (This is not
  3022.  considered an error.) If there is less than the minimum space necessary for
  3023.  a database (the size of model) in the specified database device (or in the
  3024.  default, if you don't give any names), the CREATE DATABASE statement fails.
  3025.  
  3026.  
  3027.  ────────────────────────────────────────────────────────────────────────────
  3028.  WARNING
  3029.  
  3030.  After you execute the CREATE DATABASE statement, you should dump the master
  3031.  database. This makes recovery easier and safer in case master is later
  3032.  damaged. (See Chapter 8, "Backup and Recovery.")
  3033.  ────────────────────────────────────────────────────────────────────────────
  3034.  
  3035.  
  3036.  Putting the Transaction Log into a Different Database Device
  3037.  
  3038.  SQL Server makes an entry in the transaction log each time a database page
  3039.  is modified. The logs of databases in which frequent modifications are made
  3040.  can grow to be quite large. You can always allocate more database device
  3041.  space for a log, but it is difficult to reclaim space if you allocate too
  3042.  much.
  3043.  
  3044.  You should always assign a database and its transaction log to separate
  3045.  database devices. However, for very small databases, the transaction log can
  3046.  stay in the same database device that the database itself uses. You cannot
  3047.  use the DUMP TRANSACTION statement if the database and the log are on the
  3048.  same device. In this situation, all backups must be done with DUMP DATABASE.
  3049.  
  3050.  
  3051.  For databases larger than about 4 megabytes, you should place the
  3052.  transaction log in a separate database device for these reasons:
  3053.  
  3054.  
  3055.    ■   To establish a fixed size for the log so that it will not compete with
  3056.        other database activity for space
  3057.  
  3058.    ■   To allow backups to be made with the DUMP TRANSACTION statement,
  3059.        saving time and diskettes
  3060.  
  3061.    ■   To improve performance. The improvement is especially dramatic if the
  3062.        database is used heavily
  3063.  
  3064.  
  3065.  You can decide to assign the log to a separate database device when you
  3066.  execute the CREATE DATABASE statement, or you can assign it later using
  3067.  ALTER DATABASE. Specify at least two database devices in the CREATE DATABASE
  3068.  statement, and then use the sp_logdevice system procedure to put the
  3069.  database's log into one of them.
  3070.  
  3071.  The sp_logdevice system procedure has the following syntax:
  3072.  
  3073.    sp_logdevice dbname, database_device
  3074.  
  3075.  ────────────────────────────────────────────────────────────────────────────
  3076.  dbname
  3077.    The name of the database whose transaction log you want to put in a
  3078.    specific database device.
  3079.  
  3080.  database_device
  3081.    The logical name of the database device you want to put the transaction
  3082.    log into. This database device must be an existing database device.
  3083.    Execute sp_helpdevice for a report on existing database devices.
  3084.  
  3085.  ────────────────────────────────────────────────────────────────────────────
  3086.  The first statement in the following example creates a database named
  3087.  products and assigns it 10 megabytes in the default database device and
  3088.  another 2 megabytes in the database device called logs. The second statement
  3089.  executes sp_logdevice and puts the database's transaction log table in the
  3090.  logs database device.
  3091.  
  3092.    create database products on default = 10, logs = 2
  3093.     exec sp_logdevice products, logs
  3094.  
  3095.  Only the Database Owner (in this example, the Database Owner of products)
  3096.  can execute the sp_logdevice system procedure.
  3097.  
  3098.  The size of the device required for the transaction log varies according to
  3099.  the amount of update activity and the frequency of transaction log dumps. As
  3100.  a rule, allocate to the log 10-25% of the space you allocate to the database
  3101.  itself. It is a good idea to start with a small amount of space for the log
  3102.  and then increase the size as required. Once you have assigned space to a
  3103.  log, you cannot decrease that space.
  3104.  
  3105.  ────────────────────────────────────────────────────────────────────────────
  3106.  WARNING
  3107.  
  3108.  You should dump the master database after you create a transaction log.
  3109.  ────────────────────────────────────────────────────────────────────────────
  3110.  
  3111.  
  3112.  Expanding the Transaction Log Space
  3113.  
  3114.  It makes sense to increase the amount of space allocated for the transaction
  3115.  log only if the log is in a different database device. (If you do not put
  3116.  the log into a separate device, the database and the log will compete for
  3117.  the same space.)
  3118.  
  3119.  If the log is in a separate database device, you can increase the amount of
  3120.  space allocated to it with the ALTER DATABASE statement. Then reexecute
  3121.  sp_logdevice. Here's an example:
  3122.  
  3123.    create database pubs on default = 10, logs = 2
  3124.     sp_logdevice pubs, logs
  3125.     alter database pubs on logs = 1
  3126.     sp_logdevice pubs, logs
  3127.  
  3128.  You can also increase the amount of space available to the log by adding a
  3129.  new database device. First execute the DISK INIT statement to add the
  3130.  device. Use ALTER DATABASE and sp_logdevice as in the preceding example.
  3131.  
  3132.  The amount of space allocated in the new device becomes part of the space
  3133.  available to the log. You can use as many devices per database as you wish,
  3134.  within the system limit of the number of database devices that can be added.
  3135.  
  3136.  
  3137.  To increase the amount of storage space available for the rest of the
  3138.  database, specify some device other than the log device in the ALTER
  3139.  DATABASE statement. You can put the transaction logs of more than one
  3140.  database into the same database device.
  3141.  
  3142.  
  3143.  Altering Database Size
  3144.  
  3145.  If the space allocated for a database is too small, it can be increased with
  3146.  the ALTER DATABASE statement. However, you cannot decrease the size of a
  3147.  database with the ALTER DATABASE statement. Permission for the ALTER
  3148.  DATABASE statement, like the CREATE DATABASE statement, defaults to the SA.
  3149.  ALTER DATABASE permission is automatically transferred along with a grant of
  3150.  CREATE DATABASE permission by the SA. (For more information on permissions,
  3151.  see Chapter 7, "Managing User Permissions.")
  3152.  
  3153.  The ALTER DATABASE statement is most frequently executed when SQL Server
  3154.  returns a message saying that a database has filled all of its allocated
  3155.  storage space. The minimum increase is 1 megabyte. The default is a
  3156.  1-megabyte increase in the allocated storage space in a database device. You
  3157.  can find names of default devices with sp_helpdevice.
  3158.  
  3159.  To add 1 megabyte in the default database device for the newpubs database,
  3160.  type
  3161.  
  3162.    alter database newpubs
  3163.  
  3164.  The full syntax allows you to extend a database by other amounts and to
  3165.  specify where storage space is to be added:
  3166.  
  3167.    ALTER DATABASE database_name
  3168.     [ON {DEFAULT | database_device} [= size]
  3169.      [, database_device [= size]]...]
  3170.  
  3171.  ────────────────────────────────────────────────────────────────────────────
  3172.  database_name
  3173.    The name of the database whose storage size is to be changed.
  3174.  
  3175.  ON
  3176.    A size and/or location for the database extension.
  3177.  
  3178.  DEFAULT
  3179.    Allows ALTER DATABASE to put the database extension into any default
  3180.    database device(s). To specify a size for the database extension without
  3181.    specifying the location, use "ON DEFAULT = size" (the default size is 1
  3182.    megabyte). To change a database device's status to the default, use the
  3183.    sp_diskdefault system procedure.
  3184.  
  3185.  database_device
  3186.    The logical name of the database device in which you want to locate the
  3187.    database extension. The default size of database_device is 2 megabytes. A
  3188.    database can occupy more than one database device with different amounts
  3189.    of space on each.
  3190.  
  3191.  size
  3192.    The amount of space allocated to the database extension (in megabytes).
  3193.    The minimum extension is 1 megabyte. The default values are 1 megabyte for
  3194.    a default database device and 2 megabytes for a nondefault database
  3195.    device. Legal values range from 1 to 223.
  3196.  
  3197.  ────────────────────────────────────────────────────────────────────────────
  3198.  To add 3 megabytes to the space allocated for the newpubs database in the
  3199.  database device named pubsdata1, type
  3200.  
  3201.    alter database newpubs
  3202.     on pubsdata1 = 3
  3203.  
  3204.  If SQL Server can't allocate the requested size, it will allocate as much as
  3205.  it can in each database device in half-megabyte units, with a minimum
  3206.  allocation of 1 megabyte, and report the results.
  3207.  
  3208.  To add 2 megabytes to the space allocated for newpubs in a default database
  3209.  device and 3 megabytes in pubsdata2, type
  3210.  
  3211.    alter database newpubs
  3212.      on default = 2, pubsdata2 = 3
  3213.  
  3214.  ────────────────────────────────────────────────────────────────────────────
  3215.  WARNING
  3216.  
  3217.  You should dump the master database after you execute the ALTER DATABASE
  3218.  statement.
  3219.  ────────────────────────────────────────────────────────────────────────────
  3220.  
  3221.  
  3222.  Displaying Information on Database Storage
  3223.  
  3224.  To find the name of the database device in which a particular database
  3225.  resides, use the sp_helpdb system procedure with the database name:
  3226.  
  3227.    sp_helpdb pubs
  3228.  
  3229.     name  db_size  owner dbid created   status
  3230.     -------- -------- ----- ----- ------------ --------------
  3231.     pubs  2 Mb  sa  4  Nov 13 1987  no options set
  3232.  
  3233.     (1 row affected)
  3234.  
  3235.    device   size  usage
  3236.     -------   ------  ------------------
  3237.     master    2 Mb  data and log
  3238.  
  3239.     (1 row affected)
  3240.  
  3241.  Execute sp_spaceused to get a summary of the storage space used:
  3242.  
  3243.    sp_spaceused
  3244.  
  3245.     database_name   database_size
  3246.     --------------   ---------------
  3247.     pubs     2 Mb
  3248.  
  3249.     (0 rows affected)
  3250.  
  3251.     reserved   data   index_size   unused
  3252.     ---------   ---------  ----------   -----------
  3253.     832 KB    210 KB   52 KB    570 KB
  3254.  
  3255.     (0 rows affected)
  3256.  
  3257.  The sp_spaceused report contains the following fields:
  3258.  
  3259.  ────────────────────────────────────────────────────────────────────────────
  3260.  database_name
  3261.    The name of the database whose storage space is being measured.
  3262.  
  3263.  database_size
  3264.    The amount of space allocated to the database by the CREATE DATABASE or
  3265.    ALTER DATABASE statement.
  3266.  
  3267.  reserved
  3268.    The amount of space allocated to all the tables and indexes that have been
  3269.    created in the database. (Space is allocated to database objects inside a
  3270.    database in increments of one extent, or 8 2K pages, at a time.)
  3271.  
  3272.  data
  3273.    The amount of space used by data.
  3274.  
  3275.  index_size
  3276.    The amount of space used by indexes.
  3277.  
  3278.  unused
  3279.    The amount of space that has been allocated but not actually used for data
  3280.    by tables and indexes. Adding the values in the unused, index_size, and
  3281.    data columns should give you the figure in the reserved column.
  3282.  
  3283.  ────────────────────────────────────────────────────────────────────────────
  3284.  You can also use sp_spaceused with a database object name as its parameter
  3285.  and get a report on the space used by that object. For example:
  3286.  
  3287.    sp_spaceused titles
  3288.  
  3289.     name  rows  reserved data  index_size          unused
  3290.     ------  ------  --------- ------  ----------   ------
  3291.     titles   18   48 KB  6 KB  4 KB   38 KB
  3292.  
  3293.     (0 rows affected)
  3294.  
  3295.  Executing sp_spaceused regularly lets you monitor the amount of database
  3296.  space available. For example, if the value of reserved is close to the total
  3297.  database_size, you are close to running out of space for new objects. If
  3298.  unused is also quite small, you are close to running out of space for
  3299.  additional data as well.
  3300.  
  3301.  It is a good idea to execute sp_spaceused regularly on the syslogs table
  3302.  since the transaction log can grow rapidly if there are frequent database
  3303.  modifications. This is a particular problem if the transaction log is not in
  3304.  a separate device─in which case it will be competing with the rest of the
  3305.  database for database space.
  3306.  
  3307.  You may want to write some of your own queries for additional information
  3308.  about physical storage. For example, to determine how much total storage
  3309.  space exists on SQL Server, you would query sysdevices:
  3310.  
  3311. ╓┌─────────────────┌─────────────────────────────────────────────────────────╖
  3312.  ────────────────────────────────────────────────────────────────────────────
  3313.                    select sum(high - low)
  3314.                    from sysdevices
  3315.                    where status in (2, 3)
  3316.  
  3317.                    ------------
  3318.                    7168
  3319.                    (1 row affected)
  3320.  ────────────────────────────────────────────────────────────────────────────
  3321.                   (1 row affected)
  3322.  
  3323.  
  3324.  Advanced users may want to query the sysusages table for additional
  3325.  information on login IDs. See Appendix B, "System Tables," for a description
  3326.  of this table.
  3327.  
  3328.  
  3329.  How SQL Server Allocates Space for a Database
  3330.  
  3331.  SQL Server first makes an entry for the new database in sysdatabases. Then
  3332.  it checks master..sysdevices to make sure that the database devicenames
  3333.  specified in the CREATE DATABASE statement actually exist and are database
  3334.  devices. Next it looks through master..sysusages to find space for the new
  3335.  database.
  3336.  
  3337.  The storage space from which SQL Server gathers the specified amount of
  3338.  storage need not be contiguous and can be extracted from whatever free space
  3339.  is available. The database storage space can even be drawn from more than
  3340.  one database device. Of course, a database is treated as a logical whole
  3341.  even if it is stored in more than one database device.
  3342.  
  3343.  Each piece of storage for a database must be at least 1 allocation unit─half
  3344.  a megabyte, or 256 contiguous 2K pages. The first of the 256 pages is the
  3345.  allocation page. It does not contain database rows like all the other pages.
  3346.  Rather, it contains an array that shows how the other 255 pages are used.
  3347.  
  3348.  The database storage information is listed in the master database table
  3349.  sysusages. Each row in master..sysusages represents allocation units
  3350.  assigned to some database. Thus, each database has one row in sysusages for
  3351.  each piece of noncontiguous storage space assigned to it. Each piece of
  3352.  noncontiguous storage assigned to the database can be a different size (a
  3353.  different number of allocation units).
  3354.  
  3355.  
  3356.  Dropping Databases
  3357.  
  3358.  When you drop a database, the database and all its objects are deleted.
  3359.  Dropping a database also frees the storage space that had been allocated for
  3360.  it and deletes references to it from the system tables in the master
  3361.  database.
  3362.  
  3363.  Only the Database Owner has permission to drop databases. This permission
  3364.  cannot be transferred.
  3365.  
  3366.  The DROP DATABASE statement has the following syntax:
  3367.  
  3368.    DROP DATABASE database_name [, database_name]...
  3369.  
  3370.  You can drop more than one database in a single statement. For example:
  3371.  
  3372.    drop database newpubs, newdb
  3373.  
  3374.  You must drop all the databases in a database device before you can drop the
  3375.  database device. (See the next section, "Dropping Database Devices and Dump
  3376.  Devices.")
  3377.  
  3378.  ────────────────────────────────────────────────────────────────────────────
  3379.  WARNING
  3380.  
  3381.  You should dump the master database after you drop a database.
  3382.  ────────────────────────────────────────────────────────────────────────────
  3383.  
  3384.  
  3385.  Dropping Database Devices and Dump Devices
  3386.  
  3387.  When you drop a database device or dump device, that storage space is freed
  3388.  for other use. Permission to drop database devices and dump devices defaults
  3389.  to the SA, who can transfer it.
  3390.  
  3391.  Database devices and dump devices are deleted with the sp_dropdevice system
  3392.  procedure. This procedure has the following syntax:
  3393.  
  3394.    sp_dropdevice logical_name
  3395.  
  3396.  ────────────────────────────────────────────────────────────────────────────
  3397.  WARNING
  3398.  
  3399.  You should dump the master database after you drop a database device or dump
  3400.  device. You must shut down and restart SQL Server after you drop a device.
  3401.  For instructions on shutting down and restarting SQL Server, see Chapter 4,
  3402.  "Starting and Shutting Down SQL Server."
  3403.  ────────────────────────────────────────────────────────────────────────────
  3404.  
  3405.  
  3406.  
  3407.  
  3408.  
  3409.  
  3410.  Chapter 6  Managing User Accounts
  3411.  ────────────────────────────────────────────────────────────────────────────
  3412.  
  3413.  
  3414.  Introduction
  3415.  
  3416.  The SA is usually responsible for adding login IDs to SQL Server. Once users
  3417.  can log in to SQL Server, Database Owners are usually responsible for adding
  3418.  login IDs to the appropriate databases. This chapter describes how to
  3419.  
  3420.  
  3421.    ■   Add login IDs to SQL Server
  3422.  
  3423.    ■   Add users to a specific database within SQL Server
  3424.  
  3425.    ■   Combine users into groups within a database
  3426.  
  3427.    ■   Create aliases for users within a database
  3428.  
  3429.    ■   Change database ownership
  3430.  
  3431.    ■   Display information on current users
  3432.  
  3433.  
  3434.  
  3435.  Managing Login IDs
  3436.  
  3437.  To be authorized to work on SQL Server, each user needs a login ID, a
  3438.  password, and a default database.
  3439.  
  3440.  This section describes how to
  3441.  
  3442.  
  3443.    ■   Manage login IDs with the SAF Admin menu
  3444.  
  3445.    ■   Manage login IDs by executing system procedures
  3446.  
  3447.    ■   Display information on login IDs
  3448.  
  3449.  
  3450.  
  3451.  Login IDs and Passwords
  3452.  
  3453.  The SA assigns login IDs and passwords when new users are added to SQL
  3454.  Server. This login ID and password give the user access to SQL Server but
  3455.  not to a specific database.
  3456.  
  3457.  The default password is NULL (no password). Unless the SA assigns a
  3458.  password, the user will have no password.
  3459.  
  3460.  
  3461.  Special Login IDs
  3462.  
  3463.  There are two special login IDs: sa and probe. The SA uses the sa login ID,
  3464.  and the two-phase commit service in DB-LIBRARY uses the probe login ID. Do
  3465.  not try to log in using the probe login ID. (See the SQL Server Programmer's
  3466.  Reference for more information on probe.)
  3467.  
  3468.  
  3469.  Default Databases
  3470.  
  3471.  A default database is the database to which the user is connected
  3472.  immediately after logging in to SQL Server. For example, if a user's default
  3473.  database is pubs, he or she will be connected to the pubs database after
  3474.  logging in.
  3475.  
  3476.  After assigning a default database, make sure that the user is authorized to
  3477.  access that database. (See "Managing Database Usernames," later in this
  3478.  chapter, for details.) If the user is not authorized to access the default
  3479.  database, then master will remain his or her default database (assuming that
  3480.  the master database includes the guest username). It's a good idea to assign
  3481.  default databases other than master to discourage users from creating
  3482.  objects in the master database.
  3483.  
  3484.  
  3485.  Visitor Login IDs
  3486.  
  3487.  You may want to add a login ID for visiting users (this login ID might be
  3488.  called visitor). A password and a default database can be assigned, if
  3489.  desired. Typically, visiting users are granted restricted permissions. (See
  3490.  Chapter 7, "Managing User Permissions," for information on permissions.)
  3491.  Note that the visitor login ID is different from the guest user. (See "Guest
  3492.  User," later in this chapter.)
  3493.  
  3494.  
  3495.  Managing Login IDs Using the Admin Menu
  3496.  
  3497.  The SA can use the Admin menu to add login IDs, passwords, and default
  3498.  databases. Only the SA has permission to perform these tasks.
  3499.  
  3500.  
  3501.  Adding a Login ID
  3502.  
  3503.  To add a login ID and assign a default database:
  3504.  
  3505.  
  3506.    1.  Select the Admin menu and choose Manage login IDs.
  3507.  
  3508.        The "Manage Login IDs" dialog box appears.
  3509.  
  3510.    2.  Choose Add.
  3511.  
  3512.        The "Add a Login ID" dialog box appears.
  3513.  
  3514.    3.  Complete the following information in the text boxes:
  3515.  
  3516.        ■   The login ID for the user. The login ID must follow the rules for
  3517.            identifiers (see the SQL Server Language Reference) and must be
  3518.            unique in SQL Server.
  3519.  
  3520.        ■   The user's password (enter twice). The password must follow the
  3521.            rules for identifiers (see the SQL Server Language Reference). If
  3522.            no password is entered, the new user is assigned the NULL password
  3523.            (no password) and so does not have to enter a password to log in
  3524.            to SQL Server.
  3525.  
  3526.        ■   The (optional) username. Enter this field only if you want the
  3527.            username in the default database to be different from the login
  3528.            ID. If you make no entry here, the username will default to the
  3529.            login ID. The username must follow the rules for identifiers (see
  3530.            the SQL Server Language Reference) and must be unique in SQL
  3531.            Server.
  3532.  
  3533.  
  3534.    4.  From the "Default database" text box, select the default database for
  3535.        this user.
  3536.  
  3537.    5.  Choose OK.
  3538.  
  3539.        A message appears:
  3540.  
  3541.        New login created.
  3542.  
  3543.    6.  Choose OK.
  3544.  
  3545.        A message appears:
  3546.  
  3547.        New user added.
  3548.  
  3549.    7.  Choose OK.
  3550.  
  3551.        The "Manage Login IDs" dialog box appears. The new login ID should
  3552.        appear in the "Login ID" list box.
  3553.  
  3554.    8.  Choose Done.
  3555.  
  3556.  
  3557.  
  3558.  Changing a User's Password
  3559.  
  3560.  To change a password:
  3561.  
  3562.  
  3563.    1.  Select the Admin menu and choose Manage login IDs.
  3564.  
  3565.        The "Manage Login IDs" dialog box appears.
  3566.  
  3567.    2.  From the "Login ID" list box, select the login ID of the user whose
  3568.        password you want to change.
  3569.  
  3570.    3.  Choose Change password.
  3571.  
  3572.        The "Change User Password" dialog box appears.
  3573.  
  3574.    4.  Enter the new password twice.
  3575.  
  3576.        The password must follow the rules for identifiers. (See the SQL
  3577.        Server Language Reference.)
  3578.  
  3579.    5.  Choose OK.
  3580.  
  3581.        A message appears:
  3582.  
  3583.        Password changed.
  3584.  
  3585.    6.  Choose OK.
  3586.  
  3587.        The "Manage Login IDs" dialog box appears.
  3588.  
  3589.    7.  Choose Done.
  3590.  
  3591.  
  3592.  See "Displaying Information on Login IDs," later in this chapter, for a list
  3593.  of SQL Server passwords.
  3594.  
  3595.  
  3596.  Changing a User's Default Database
  3597.  
  3598.  To change a user's default database:
  3599.  
  3600.  
  3601.    1.  Select the Admin menu and choose Manage login IDs.
  3602.  
  3603.        The "Manage Login IDs" dialog box appears.
  3604.  
  3605.    2.  From the "Login ID" list box, select the login ID of the user whose
  3606.        default database you want to change.
  3607.  
  3608.    3.  Choose Change default DB.
  3609.  
  3610.        The "Change Default Database" dialog box appears.
  3611.  
  3612.    4.  From the "New default database" list box, select the new default
  3613.        database for this user.
  3614.  
  3615.    5.  Choose OK.
  3616.  
  3617.        A message appears:
  3618.  
  3619.        Default database changed.
  3620.  
  3621.    6.  Choose OK.
  3622.  
  3623.        The "Manage Login IDs" dialog box appears.
  3624.  
  3625.    7.  Choose Done.
  3626.  
  3627.  
  3628.  
  3629.  Deleting a Login ID
  3630.  
  3631.  To delete a login ID:
  3632.  
  3633.  
  3634.    1.  Select the Admin menu and choose Manage login IDs.
  3635.  
  3636.        The "Manage Login IDs" dialog box appears.
  3637.  
  3638.    2.  From the "Login ID" list box, select the login ID for the user to be
  3639.        deleted.
  3640.  
  3641.    3.  Choose Delete.
  3642.  
  3643.        A message appears:
  3644.  
  3645.        Login dropped.
  3646.  
  3647.    4.  Choose OK.
  3648.  
  3649.        The "Manage Login IDs" dialog box appears. The deleted login ID should
  3650.        not appear in the "Login ID" list box.
  3651.  
  3652.    5.  Choose Done.
  3653.  
  3654.  
  3655.  After you delete a login ID, the user cannot log in to SQL Server.
  3656.  
  3657.  ────────────────────────────────────────────────────────────────────────────
  3658.  NOTE
  3659.  
  3660.  Remember to delete the username from all databases associated with the login
  3661.  ID you are deleting. (See "Deleting a Username," later in this chapter.)
  3662.  ────────────────────────────────────────────────────────────────────────────
  3663.  
  3664.  
  3665.  Managing Login IDs Using System Procedures
  3666.  
  3667.  You can add login IDs, change a user's password, change a user's default
  3668.  database, and delete login IDs using system procedures.
  3669.  
  3670.  
  3671.  Adding a Login ID
  3672.  
  3673.  To add a login ID, use the sp_addlogin system procedure.
  3674.  
  3675.  The sp_addlogin system procedure has the following syntax:
  3676.  
  3677.    sp_addlogin login_id [, password [, defaultdb]]
  3678.  
  3679.  ────────────────────────────────────────────────────────────────────────────
  3680.  login_id
  3681.    The user's login ID. Login IDs must follow rules for identifiers and must
  3682.    be unique on SQL Server.
  3683.  
  3684.  password
  3685.    The user's password. If no password is given, the default password is NULL
  3686.    (no password).
  3687.  
  3688.  defaultdb
  3689.    The name of the user's default database─the database to which the user is
  3690.    connected when he or she logs in. If no defaultdb is given, the default is
  3691.    master.
  3692.  
  3693.  ────────────────────────────────────────────────────────────────────────────
  3694.  The following statement sets up an account for the user maryd with the
  3695.  default password (NULL) and the default database (master).
  3696.  
  3697.    sp_addlogin "maryd"
  3698.  
  3699.  Once this statement is executed, maryd can log in to SQL Server. If the
  3700.  master database contains a guest user, maryd is automatically treated as a
  3701.  guest user in master unless she has been specifically given access to
  3702.  master.
  3703.  
  3704.  The following statement sets up a login ID and a password for user
  3705.  omar_khayyam and makes pubs his default database:
  3706.  
  3707.    sp_addlogin "omar_khayyam", rubaiyat, pubs
  3708.  
  3709.  If omar_khayyam later decides to change his default database, he can do so
  3710.  with the sp_defaultdb system procedure. For information on sp_defaultdb, see
  3711.  "Changing a User's Default Database," later in this chapter.
  3712.  
  3713.  ────────────────────────────────────────────────────────────────────────────
  3714.  NOTE
  3715.  
  3716.  Remember to add the new username to the default database you have just
  3717.  assigned. (See "Adding a Username," later in this chapter, for more
  3718.  information.)
  3719.  ────────────────────────────────────────────────────────────────────────────
  3720.  
  3721.  
  3722.  Changing a User's Password
  3723.  
  3724.  To change a user's password, use the sp_password system procedure. Any user
  3725.  can use sp_password to change his or her own password.
  3726.  
  3727.  The sp_password system procedure has the following syntax:
  3728.  
  3729.    sp_password old, new [, login_id]
  3730.  
  3731.  ────────────────────────────────────────────────────────────────────────────
  3732.  old
  3733.    The user's old password. To locate existing passwords, see "Displaying
  3734.    Information on Login IDs," later in this chapter.
  3735.  
  3736.  new
  3737.    The user's new password.
  3738.  
  3739.  login_id
  3740.    The user's login ID. Only the SA can use this option to change a user's
  3741.    password.
  3742.  
  3743.  ────────────────────────────────────────────────────────────────────────────
  3744.  For example, Mary can change her password from the default NULL to pine with
  3745.  this statement:
  3746.  
  3747.    sp_password null, pine
  3748.  
  3749.  Notice that null and pine are not enclosed in quotes.
  3750.  
  3751.  If the SA doesn't like Mary's new password, he or she can change it with
  3752.  this statement:
  3753.  
  3754.    sp_password pine, spruce, mary
  3755.  
  3756.  The password is entered into the master.dbo.syslogins.password field.
  3757.  Permission to read this field is denied to all users except the SA.
  3758.  
  3759.  
  3760.  Changing a User's Default Database
  3761.  
  3762.  To change a user's default database, use the sp_defaultdb system procedure.
  3763.  Any user can use sp_defaultdb to change his or her own default database.
  3764.  
  3765.  The sp_defaultdb system procedure has the following syntax:
  3766.  
  3767.    sp_defaultdb login_id, defaultdb
  3768.  
  3769.  ────────────────────────────────────────────────────────────────────────────
  3770.  login_id
  3771.    The login ID of the user
  3772.  
  3773.  defaultdb
  3774.    The name of the user's default database
  3775.  
  3776.  ────────────────────────────────────────────────────────────────────────────
  3777.  Once the procedure is executed, the user will be connected to the new
  3778.  default database the next time he or she logs in.
  3779.  
  3780.  However, sp_defaultdb does not automatically give the user access to the new
  3781.  default database. Unless the Database Owner has set up access with
  3782.  sp_adduser, sp_addalias, or with a guest user mechanism, the user is
  3783.  connected to master even after his or her default database has been changed.
  3784.  
  3785.  
  3786.  Here's how Omar Khayyam would change his default database to accounting:
  3787.  
  3788.    sp_defaultdb "omar_khayyam", accounting
  3789.  
  3790.  The SA could change Omar's default database from accounting to purchasing:
  3791.  
  3792.    sp_defaultdb "omar_khayyam", purchasing
  3793.  
  3794.  
  3795.  Deleting a Login ID
  3796.  
  3797.  To delete a login ID, use the sp_droplogin system procedure.
  3798.  
  3799.  The sp_droplogin system procedure has the following syntax:
  3800.  
  3801.    sp_droplogin login_id
  3802.  
  3803.  ────────────────────────────────────────────────────────────────────────────
  3804.  login_id
  3805.    The user's login ID
  3806.  
  3807.  ────────────────────────────────────────────────────────────────────────────
  3808.  Displaying Information on Login IDs
  3809.  
  3810.  To see a list of users' login IDs, passwords, and default databases, execute
  3811.  this SQL statement from the master database:
  3812.  
  3813.    select name, password, dbname
  3814.     from syslogins
  3815.  
  3816.  A report similar to the one following appears:
  3817.  
  3818.    name   password  dbname
  3819.     -----------  ------------ ----------
  3820.     sa        master
  3821.     margaret  prx7   pubs
  3822.     william   bill   master
  3823.     visitor   visitor   pubs
  3824.  
  3825.     (4 rows affected)
  3826.  
  3827.  The report headings have the following descriptions:
  3828.  
  3829.  ────────────────────────────────────────────────────────────────────────────
  3830.  name
  3831.    Login ID
  3832.  
  3833.  password
  3834.    Password (this column appears only if you are logged in as sa)
  3835.  
  3836.  dbname
  3837.    Default database name
  3838.  
  3839.  ────────────────────────────────────────────────────────────────────────────
  3840.  Advanced users may want to query the syslogins system table. See Appendix B,
  3841.  "System Tables," for information on the structure of this table.
  3842.  
  3843.  
  3844.  Managing Database Usernames
  3845.  
  3846.  Users who have been given login IDs on SQL Server still need permission to
  3847.  access databases. Permission to access databases is granted by each Database
  3848.  Owner.
  3849.  
  3850.  Users who have been given access to a database still need permission to do
  3851.  things inside it: to read data, modify data, and use SQL statements. These
  3852.  permissions are set up by the Database Owner or the database object owner.
  3853.  They are discussed in Chapter 7, "Managing User Permissions."
  3854.  
  3855.  This section describes:
  3856.  
  3857.  
  3858.    ■   How to manage usernames with the SAF Admin menu
  3859.  
  3860.    ■   How to manage usernames by executing system procedures
  3861.  
  3862.    ■   How to display information on usernames
  3863.  
  3864.  
  3865.  
  3866.  Usernames
  3867.  
  3868.  A username is required for a user to access an SQL Server database. It is
  3869.  different from a login ID, which gives the user access to SQL Server but not
  3870.  to any user databases.
  3871.  
  3872.  Usernames are supplied to accommodate users' preferences. For example, if
  3873.  there are five SQL Server users named Mary, all of them must have different
  3874.  login IDs. Mary Doe might log in as maryd, Mary Jones as maryj, and so on.
  3875.  However, if the Marys don't use the same databases, each might prefer to be
  3876.  known simply as mary inside a particular database.
  3877.  
  3878.  Each user may belong to only one group in addition to the public group. (See
  3879.  "Managing Database Groups," later in this chapter, for details on groups.)
  3880.  
  3881.  The only special usernames are dbo for Database Owner and guest for guest
  3882.  users.
  3883.  
  3884.  
  3885.  Guest User
  3886.  
  3887.  A guest username is often set up to allow limited access to a database to
  3888.  all SQL Server login IDs. If, for example, Jim does not have a username in
  3889.  the doc database, but the doc database has a guest username set up, then Jim
  3890.  can use doc. A guest user in a user database allows an owner to extend
  3891.  database use to all SQL Server login IDs without adding a username for each
  3892.  user. Guests usually have very limited permissions. (See Chapter 7,
  3893.  "Managing User Permissions," for details on permissions.)
  3894.  
  3895.  Initially, guest users inherit the permissions of the public group. The
  3896.  Database Owner and database objects owners can change these permissions to
  3897.  make the permissions of guest either more restrictive or less restrictive
  3898.  than those of public.
  3899.  
  3900.  When SQL Server is installed, both the master and pubs databases include a
  3901.  guest username.
  3902.  
  3903.  The guest user entry in pubs allows new SQL Server users to follow the
  3904.  examples and to engage in a certain amount of experimentation. The guest in
  3905.  pubs is given a wide range of permissions.
  3906.  
  3907.  If you want all new databases to have a guest user, add guest to the model
  3908.  database.
  3909.  
  3910.  
  3911.  Managing Usernames Using the Admin Menu
  3912.  
  3913.  The SA or Database Owner can use the Admin menu to add users, change a
  3914.  user's group, and delete users. Only the SA and the Database Owner have
  3915.  permission to perform these tasks.
  3916.  
  3917.  
  3918.  Adding a Username
  3919.  
  3920.  When you add a user to a database, you can optionally specify a groupname.
  3921.  If no groupname is specified, the user is made a member of the default
  3922.  group, public. The user to be added must have a login ID on the server.
  3923.  
  3924.  To add a user to a database and assign a groupname:
  3925.  
  3926.  
  3927.    1.  Select the Admin menu and choose Manage usernames.
  3928.  
  3929.        The "Manage Usernames" dialog box appears.
  3930.  
  3931.    2.  From the "Database" list box, select the database to which you want to
  3932.        add a user.
  3933.  
  3934.    3.  Choose OK.
  3935.  
  3936.        The "Manage Usernames" dialog box appears.
  3937.  
  3938.    4.  Choose Add.
  3939.  
  3940.        The "Add a Username" dialog box appears.
  3941.  
  3942.    5.  From the "Login ID" list box, select the name of the user to be added
  3943.        to the database.
  3944.  
  3945.    6.  If you want this user to be a member of a group, select a groupname
  3946.        from the "Groupname" dialog box.
  3947.  
  3948.    7.  In the "Username in database" text box, type the username for this
  3949.        person.
  3950.  
  3951.        If you want the username to be the same as the login ID, leave this
  3952.        text box blank.
  3953.  
  3954.        The username must follow the rules for identifiers. (See the SQL
  3955.        Server Language Reference.)
  3956.  
  3957.    8.  Choose OK.
  3958.  
  3959.        A message appears:
  3960.  
  3961.        New user added.
  3962.  
  3963.    9.  Choose OK.
  3964.  
  3965.       The "Manage Usernames" dialog box appears. The new username should
  3966.       appear in the "Username" list box.
  3967.  
  3968.    10. Choose Done.
  3969.  
  3970.  
  3971.  
  3972.  Changing a User's Group
  3973.  
  3974.  Each user can be a member of only one group at a time (in addition to the
  3975.  public group). To change a user's group:
  3976.  
  3977.  
  3978.    1.  Select the Admin menu and choose Manage usernames.
  3979.  
  3980.        The "Manage Usernames" dialog box appears.
  3981.  
  3982.    2.  From the "Database" list box, select the database in which you want to
  3983.        change a group assignment.
  3984.  
  3985.    3.  Choose OK.
  3986.  
  3987.        The "Manage Usernames" dialog box appears.
  3988.  
  3989.    4.  From the "Username" list box, select the name of the user whose group
  3990.        you want to change.
  3991.  
  3992.    5.  Choose Change Group.
  3993.  
  3994.        The "Change Group" dialog box appears.
  3995.  
  3996.    6.  In the "New usergroup" list box, select a new group.
  3997.  
  3998.    7.  Choose OK.
  3999.  
  4000.        A message appears:
  4001.  
  4002.        Group changed.
  4003.  
  4004.    8.  Choose OK.
  4005.  
  4006.        The "Manage Usernames" dialog box appears.
  4007.  
  4008.    9.  Choose Done.
  4009.  
  4010.  
  4011.  
  4012.  Deleting a Username
  4013.  
  4014.  You can delete a username from a database unless the user owns objects. To
  4015.  delete a user from a database:
  4016.  
  4017.  
  4018.    1.  Select the Admin menu and choose Manage usernames.
  4019.  
  4020.        The "Manage Usernames" dialog box appears.
  4021.  
  4022.    2.  From the "Database" list box, select the database from which you want
  4023.        to delete a user.
  4024.  
  4025.    3.  Choose OK.
  4026.  
  4027.        The "Manage Usernames" dialog box appears.
  4028.  
  4029.    4.  From the "Username" list box, select the username you want to delete.
  4030.  
  4031.    5.  Choose Delete.
  4032.  
  4033.        A message appears:
  4034.  
  4035.        User has been dropped from current database.
  4036.  
  4037.    6.  Choose OK.
  4038.  
  4039.        The "Manage Usernames" dialog box appears. The username you deleted
  4040.        should not appear in the "Username" list box.
  4041.  
  4042.    7.  Choose Done.
  4043.  
  4044.  
  4045.  Before a username is deleted, SQL Server checks the current database to make
  4046.  sure the user being deleted does not own any objects or have any aliases.
  4047.  
  4048.  
  4049.  Managing Usernames Using System Procedures
  4050.  
  4051.  You can add usernames, change a user's group, and delete usernames using
  4052.  system procedures.
  4053.  
  4054.  
  4055.  Adding a Username
  4056.  
  4057.  To add a username to the current database, use the sp_adduser system
  4058.  procedure.
  4059.  
  4060.  The sp_adduser system procedure has the following syntax:
  4061.  
  4062.    sp_adduser login_id [, username [, grpname]]
  4063.  
  4064.  ────────────────────────────────────────────────────────────────────────────
  4065.  login_id
  4066.    The user's login ID.
  4067.  
  4068.  username
  4069.    A name for this user in the current database. Omitting this optional
  4070.    parameter causes the username to default to the user's login ID.
  4071.  
  4072.  grpname
  4073.    The name of an existing group in the database. If you don't specify a
  4074.    group, the user becomes a member of the default group, public.
  4075.  
  4076.  ────────────────────────────────────────────────────────────────────────────
  4077.  The following statements, executed by the owner of the pubs database, allow
  4078.  maryh of the (already existing) engineering group access to pubs:
  4079.  
  4080.    use pubs
  4081.     <execute>
  4082.     sp_adduser maryh, mary, eng
  4083.  
  4084.  
  4085.  Changing a User's Group
  4086.  
  4087.  Users who already have access to the database can be made members of an
  4088.  existing group with sp_changegroup. The sp_changegroup system procedure
  4089.  changes an existing user's group whether the user is a member of the default
  4090.  group, public, or of some other group. At any one time, each user can be a
  4091.  member of only one group.
  4092.  
  4093.  The sp_changegroup system procedure has the following syntax:
  4094.  
  4095.    sp_changegroup grpname, username
  4096.  
  4097.  ────────────────────────────────────────────────────────────────────────────
  4098.  grpname
  4099.    The new groupname. Because PUBLIC is a also keyword, you must specify the
  4100.    group public in quotation marks in this context.
  4101.  
  4102.  username
  4103.    The user's name in the current database.
  4104.  
  4105.  ────────────────────────────────────────────────────────────────────────────
  4106.  For example, here's how you'd change Jim to the management group:
  4107.  
  4108.    sp_changegroup manage, jim
  4109.  
  4110.  Be careful not to confuse this capability with the alias mechanism, which
  4111.  maps the identity and permissions of one user to another. (See "Managing
  4112.  Aliases," later in this chapter.)
  4113.  
  4114.  Groups are used in granting and revoking permissions. Groups are discussed
  4115.  in "Managing Database Groups," later in this chapter.
  4116.  
  4117.  
  4118.  Deleting a Username
  4119.  
  4120.  To delete a username from a database, use the sp_dropuser system procedure.
  4121.  
  4122.  
  4123.  The sp_dropuser system procedure has the following syntax:
  4124.  
  4125.    sp_dropuser username
  4126.  
  4127.  ────────────────────────────────────────────────────────────────────────────
  4128.  username
  4129.    The user's name in the current database
  4130.  
  4131.  ─────────────────────────────────────────────────────────────────────────────
  4132.  WARNING
  4133.  
  4134.  Do not drop users who own database objects. Before dropping a user, first
  4135.  check to see if that user owns any database objects. If the user does own
  4136.  database objects, drop the objects or change their ownership before dropping
  4137.  the user.
  4138.  ────────────────────────────────────────────────────────────────────────────
  4139.  
  4140.  
  4141.  Displaying Information on Usernames
  4142.  
  4143.  To display a report on database users, use the sp_helpuser system procedure.
  4144.  
  4145.  
  4146.  The sp_helpuser system procedure has the following syntax:
  4147.  
  4148.    sp_helpuser [username]
  4149.  
  4150.  ────────────────────────────────────────────────────────────────────────────
  4151.  username
  4152.    The user's name in the current database. If you don't specify a name, the
  4153.    system procedure reports on all users of the current database.
  4154.  
  4155.  ────────────────────────────────────────────────────────────────────────────
  4156.  A sample of a report on all users is shown below:
  4157.  
  4158. ╓┌─┌──────────────────┌─────────┌────────────┌────────────┌──────────────────╖
  4159.  ────────────────────────────────────────────────────────────────────────────
  4160.  ────────────────────────────────────────────────────────────────────────────
  4161.    sp_helpuser
  4162.  
  4163.    Users_name         ID_in_db  Group_name   Login_name   Default_db
  4164.    ----------         --------  -----------  -----------  ----------
  4165.    dbo                1         public       sa           master
  4166.    marcy              4         public       marcy        pubs
  4167.    sandy              3         public       sandy        pubs
  4168.    judy               5         public       judy         pubs
  4169.    linda              6         public       linda        master
  4170.    anne               2         public       anne         pubs
  4171.    jim                7         senioreng    jim          master
  4172.    (7 rows affected)
  4173.  
  4174.  
  4175.  The fields of the report have the following meaning:
  4176.  
  4177.  ────────────────────────────────────────────────────────────────────────────
  4178.  Users_name
  4179.    Username
  4180.  
  4181.  ID_in_db
  4182.    ID in database, assigned by SQL Server
  4183.  
  4184.  Group_name
  4185.    Groupname
  4186.  
  4187.  Login_name
  4188.    Login ID
  4189.  
  4190.  Default_db
  4191.    Default database
  4192.  
  4193.  ────────────────────────────────────────────────────────────────────────────
  4194.  Advanced users may want to query the sysusers system table for additional
  4195.  information on usernames. See Appendix B, "System Tables," for a description
  4196.  of this table.
  4197.  
  4198.  
  4199.  Managing Database Groups
  4200.  
  4201.  Database groups are made up of several users who all have the same
  4202.  permissions. This section describes how to:
  4203.  
  4204.  
  4205.    ■   Manage groups with the SAF Admin menu
  4206.  
  4207.    ■   Manage groups by executing system procedures
  4208.  
  4209.    ■   Display information on groups
  4210.  
  4211.  
  4212.  
  4213.  Groups
  4214.  
  4215.  Groups are used as a collective name for granting and revoking permissions;
  4216.  they provide a convenient way to grant or revoke permissions to more than
  4217.  one user in a single statement. Every SQL Server user always belongs to the
  4218.  public group. In addition, every user may belong to one additional group.
  4219.  
  4220.  
  4221.  Public Group
  4222.  
  4223.  A default group, public, is set up each time a database is created. A
  4224.  database user is a member of the public group and possibly one other group.
  4225.  
  4226.  
  4227.  
  4228.  Managing Database Groups Using the Admin Menu
  4229.  
  4230.  The SA and Database Owner can use the Admin menu to add and delete database
  4231.  groups. Only the SA and Database Owner have permission to perform these
  4232.  tasks.
  4233.  
  4234.  
  4235.  Adding a Group
  4236.  
  4237.  To add a group to a database:
  4238.  
  4239.  
  4240.    1.  Select the Admin menu and choose Manage groups.
  4241.  
  4242.        The "Manage Groups" dialog box appears.
  4243.  
  4244.    2.  From the "Database" list box, select the database to which you want to
  4245.        add a group.
  4246.  
  4247.    3.  Choose OK.
  4248.  
  4249.        The "Manage Groups" dialog box appears.
  4250.  
  4251.    4.  Choose Add.
  4252.  
  4253.        The "Add a Groupname" dialog box appears.
  4254.  
  4255.    5.  In the "Groupname" text box, enter the name of the new group you want
  4256.        to add.
  4257.  
  4258.        The groupname must follow the rules for identifiers.
  4259.  
  4260.    6.  Choose OK.
  4261.  
  4262.        A message appears:
  4263.  
  4264.        New group added.
  4265.  
  4266.    7.  Choose OK.
  4267.  
  4268.        The "Manage Groups" dialog box appears. The new groupname should
  4269.        appear in the dialog box.
  4270.  
  4271.    8.  Choose Done.
  4272.  
  4273.  
  4274.  After adding a group, if you want to add group members who already have
  4275.  access to the database, see "Changing a User's Group," earlier in this
  4276.  chapter, for instructions. To add group members who do not have access to
  4277.  the database, see "Adding a Username," earlier in this chapter.
  4278.  
  4279.  
  4280.  Deleting a Group
  4281.  
  4282.  Before you can delete a group, you must remove all members from the group.
  4283.  You remove members from a group by changing the group they belong to (which
  4284.  may be public or some other group). See "Changing a User's Group," earlier
  4285.  in this chapter, for details on changing a user's group.
  4286.  
  4287.  Any group except public can be deleted.
  4288.  
  4289.  To delete a group:
  4290.  
  4291.  
  4292.    1.  Select the Admin menu and choose Manage groups.
  4293.  
  4294.        The "Manage Groups" dialog box appears.
  4295.  
  4296.    2.  From the "Database" list box, select the database from which you want
  4297.        to delete a group.
  4298.  
  4299.    3.  Choose OK.
  4300.  
  4301.        The "Manage Groups" dialog box appears.
  4302.  
  4303.    4.  From the "Groups" list box, select the name of the group to be
  4304.        deleted.
  4305.  
  4306.    5.  Choose Delete.
  4307.  
  4308.        A message appears:
  4309.  
  4310.        Group has been dropped.
  4311.  
  4312.    6.  Choose OK.
  4313.  
  4314.        The "Manage Groups" dialog box appears.
  4315.  
  4316.    7.  Choose Done.
  4317.  
  4318.  
  4319.  
  4320.  Managing Groups Using System Procedures
  4321.  
  4322.  You can add or delete a group using system procedures.
  4323.  
  4324.  
  4325.  Adding a Group
  4326.  
  4327.  To add a group to the current database, use the sp_addgroup system
  4328.  procedure.
  4329.  
  4330.  The sp_addgroup system procedure has the following syntax:
  4331.  
  4332.    sp_addgroup grpname
  4333.  
  4334.  ────────────────────────────────────────────────────────────────────────────
  4335.  grpname
  4336.    The name of the group. Groupnames must follow the rules for identifiers.
  4337.  
  4338.  ────────────────────────────────────────────────────────────────────────────
  4339.  Once a group is created, the Database Owner can add new users to it with the
  4340.  sp_adduser system procedure, discussed under "Adding a Username," earlier in
  4341.  this chapter.
  4342.  
  4343.  Users who already have access to the database can be made members of a group
  4344.  with sp_changegroup. (See "Changing a User's Group," earlier in this
  4345.  chapter, for more information.)
  4346.  
  4347.  
  4348.  Deleting a Group
  4349.  
  4350.  To delete a group, use the sp_dropgroup system procedure.
  4351.  
  4352.  The sp_dropgroup system procedure has the following syntax:
  4353.  
  4354.    sp_dropgroup grpname
  4355.  
  4356.  ────────────────────────────────────────────────────────────────────────────
  4357.  grpname
  4358.    The name of a group in the current database.
  4359.  
  4360.  ────────────────────────────────────────────────────────────────────────────
  4361.  For example, to delete the senior engineering group, execute this statement:
  4362.  
  4363.  
  4364.    sp_dropgroup senioreng
  4365.  
  4366.  You cannot drop a group that has members. To remove users from a group,
  4367.  execute sp_changegroup, discussed in "Changing a User's Group," earlier in
  4368.  this chapter.
  4369.  
  4370.  
  4371.  Displaying Information on Groups
  4372.  
  4373.  To display a report on groups within the current database, use the
  4374.  sp_helpgroup system procedure.
  4375.  
  4376.  The sp_helpgroup system procedure has the following syntax:
  4377.  
  4378.    sp_helpgroup [grpname]
  4379.  
  4380.  ────────────────────────────────────────────────────────────────────────────
  4381.  grpname
  4382.    The name of a group in the current database. If this option is omitted,
  4383.    all groups in the current database are displayed. Because PUBLIC is also a
  4384.    keyword, you must specify the group public in quotation marks in this
  4385.    context.
  4386.  
  4387.  ────────────────────────────────────────────────────────────────────────────
  4388.  The following example displays information about the hackers group:
  4389.  
  4390. ╓┌─┌─────────────────────┌─────────┌────────────────┌────────────────────────╖
  4391.  ────────────────────────────────────────────────────────────────────────────
  4392.    sp_helpgroup hackers
  4393.  
  4394.    Group_name            Group_id  Users_in_group   Userid
  4395.    ----------            --------  -----------      -------
  4396.    hackers               16384     ann              4
  4397.    hackers               16384     judy             3
  4398.  
  4399.    (2 rows affected)
  4400.  
  4401.  
  4402.  The report headings have the following descriptions:
  4403.  
  4404.  ────────────────────────────────────────────────────────────────────────────
  4405.  Group_name
  4406.    Groupname
  4407.  
  4408.  Group_id
  4409.    Number assigned by SQL Server
  4410.  
  4411.  Users_in_group
  4412.    Username in the database
  4413.  
  4414.  Userid
  4415.    Number assigned by SQL Server
  4416.  
  4417.  ────────────────────────────────────────────────────────────────────────────
  4418.  Advanced users may want to query the sysusers system table for additional
  4419.  information on groups. See Appendix B, "System Tables," for a description of
  4420.  this table.
  4421.  
  4422.  
  4423.  Managing Aliases
  4424.  
  4425.  With an alias, you can assume all the permissions of another user in a
  4426.  different database.
  4427.  
  4428.  This section describes how to:
  4429.  
  4430.  
  4431.    ■   Manage aliases with the SAF Admin menu
  4432.  
  4433.    ■   Manage aliases IDs by executing system procedures
  4434.  
  4435.    ■   Display information on aliases
  4436.  
  4437.  
  4438.  
  4439.  Aliases
  4440.  
  4441.  An alias allows a user to access a database and to assume all the
  4442.  permissions of a user in that database. The user who assumes the permissions
  4443.  of another user cannot have a username in the database in which he or she
  4444.  will assume permissions.
  4445.  
  4446.  One use for the alias mechanism is to allow several people to assume the
  4447.  role of Database Owner in a database.
  4448.  
  4449.  For example, suppose that Bob is the Database Owner of the reservations
  4450.  database. Bob is going on vacation and Mary has been assigned to take over
  4451.  as the reservations Database Owner while Bob is gone. Mary is not a user of
  4452.  reservations, but by creating an alias between Mary and Bob, Mary can use
  4453.  the reservations database and assume all Bob's permissions as Database
  4454.  Owner.
  4455.  
  4456.  
  4457.  Managing Aliases Using the Admin Menu
  4458.  
  4459.  The SA and Database Owner can use the Admin menu to create and remove
  4460.  aliases. Only the SA and Database Owner have permission to perform these
  4461.  tasks.
  4462.  
  4463.  
  4464.  Creating an Alias
  4465.  
  4466.  To create an alias:
  4467.  
  4468.  
  4469.    1.  Select the Admin menu and choose Manage aliases.
  4470.  
  4471.        The "Manage Aliases" dialog box appears.
  4472.  
  4473.    2.  From the "Database" list box, select the database in which you want to
  4474.        create an alias.
  4475.  
  4476.    3.  Choose OK.
  4477.  
  4478.        The "Manage Aliases" dialog box appears.
  4479.  
  4480.    4.  Choose Create.
  4481.  
  4482.        The "Create an Alias" dialog box appears.
  4483.  
  4484.    5.  In the "Login ID" list box, select the login ID of the user who will
  4485.        be linked with a username in the database you selected in step 2.
  4486.  
  4487.    6.  In the "Associated username" list box, select the username that will
  4488.        be used as an alias by the login ID you just selected.
  4489.  
  4490.    7.  Choose Create.
  4491.  
  4492.        A message appears:
  4493.  
  4494.        Alias user added.
  4495.  
  4496.    8.  Choose OK.
  4497.  
  4498.        The "Manage Aliases" dialog box appears.
  4499.  
  4500.    9.  Choose Done.
  4501.  
  4502.  
  4503.  
  4504.  Removing an Alias
  4505.  
  4506.  To remove an alias:
  4507.  
  4508.  
  4509.    1.  Select the Admin menu and choose Manage aliases.
  4510.  
  4511.        The "Manage Aliases" dialog box appears.
  4512.  
  4513.    2.  From the "Database" list box, select the database from which you want
  4514.        to remove an alias.
  4515.  
  4516.    3.  Choose OK.
  4517.  
  4518.        The "Manage Aliases" dialog box appears.
  4519.  
  4520.    4.  From the "User login ID/alias username" list box, select the login
  4521.        ID/alias that you want to remove.
  4522.  
  4523.    5.  Choose Remove.
  4524.  
  4525.        A message appears:
  4526.  
  4527.        Alias user dropped.
  4528.  
  4529.    6.  Choose OK.
  4530.  
  4531.        The "Manage Aliases" dialog box appears.
  4532.  
  4533.    7.  Choose Done.
  4534.  
  4535.  
  4536.  
  4537.  Managing Aliases Using System Procedures
  4538.  
  4539.  You can create and remove aliases by using system procedures.
  4540.  
  4541.  
  4542.  Creating an Alias
  4543.  
  4544.  To create an alias in the current database, use the sp_addalias system
  4545.  procedure.
  4546.  
  4547.  The sp_addalias system procedure has the following syntax:
  4548.  
  4549.    sp_addalias login_id, username
  4550.  
  4551.  ────────────────────────────────────────────────────────────────────────────
  4552.  login_id
  4553.    The name of the user who wants an alternate identity in the current
  4554.    database.
  4555.  
  4556.  username
  4557.    The name of the database user to whom the first user wishes to be linked.
  4558.  
  4559.  ────────────────────────────────────────────────────────────────────────────
  4560.  Executing sp_addalias maps the user with the specified login ID to the user
  4561.  with the specified username.
  4562.  
  4563.  As an example, suppose that Mary is the Database Owner of the pubs database.
  4564.  She wants both Jane and Sarah to use the database as if they were its
  4565.  owners. Jane and Sarah have login IDs on SQL Server but are not authorized
  4566.  to use Mary's database. Mary executes these statements:
  4567.  
  4568.    use pubs
  4569.     <execute>
  4570.     sp_addalias jane, dbo
  4571.     <execute>
  4572.     sp_addalias sarah, dbo
  4573.  
  4574.  Now either Jane or Sarah can access Mary's database and be recognized as the
  4575.  owner.
  4576.  
  4577.  
  4578.  Removing an Alias
  4579.  
  4580.  To drop an alias, use the sp_dropalias system procedure.
  4581.  
  4582.  The sp_dropalias system procedure has the following syntax:
  4583.  
  4584.    sp_dropalias login_id
  4585.  
  4586.  ────────────────────────────────────────────────────────────────────────────
  4587.  login_id
  4588.    The login ID of the user who has an alias
  4589.  
  4590.  ────────────────────────────────────────────────────────────────────────────
  4591.  Once a user's alias is dropped, the user no longer has access to the
  4592.  database unless his or her name is added to the database or the database has
  4593.  a guest user.
  4594.  
  4595.  
  4596.  Displaying Information on Aliases
  4597.  
  4598.  To display a report on groups within the current database, use the
  4599.  sp_helpuser system procedure.
  4600.  
  4601.  The sp_helpuser system procedure has the following syntax:
  4602.  
  4603.    sp_helpuser [username]
  4604.  
  4605.  ────────────────────────────────────────────────────────────────────────────
  4606.  username
  4607.    The username in the current database. If you don't specify a username, the
  4608.    system procedure reports on all users of the current database.
  4609.  
  4610.  ────────────────────────────────────────────────────────────────────────────
  4611.  In the following sample report, four login IDs (andy, christa, howard, and
  4612.  linda) have the alias dbo in the current database.
  4613.  
  4614. ╓┌─┌───────────────────────┌─────────┌───────────┌───────────┌───────────────╖
  4615.  ────────────────────────────────────────────────────────────────────────────
  4616.    sp_helpuser dbo
  4617.  
  4618.    Users_name              ID_in_db  Group_name  Login_name  Default_db
  4619.    ----------              --------  ----------  ----------  ----------
  4620.    dbo                     1         public      sa          master
  4621.  
  4622.  ────────────────────────────────────────────────────────────────────────────
  4623. 
  4624.    (1 row affected)
  4625.  
  4626.    Users aliased to user.
  4627.  
  4628.    Login_name
  4629.    -----------
  4630.    andy
  4631.    christa
  4632.    howard
  4633.    linda
  4634.    (4 rows affected)
  4635.  
  4636.  
  4637.  Advanced users may want to query the sysalternates system table for
  4638.  additional information on login IDs. See Appendix B, "System Tables," for a
  4639.  description of this table.
  4640.  
  4641.  
  4642.  Changing a Database Owner
  4643.  
  4644.  Ownership of a database can be transferred to another user. The new owner
  4645.  must already have a login ID on SQL Server, but must not have a username or
  4646.  alias in the database. If you want to assign database ownership to such a
  4647.  user, drop his or her database name and aliases before changing ownership.
  4648.  
  4649.  After you have assigned a new owner, the new owner is known as dbo in the
  4650.  database. If you (as SA) want to grant permissions to this new owner, grant
  4651.  them to dbo─the user is no longer known in the database under any other
  4652.  name.
  4653.  
  4654.  This section describes how to:
  4655.  
  4656.  
  4657.    ■   Change a database owner with the SAF Admin menu
  4658.  
  4659.    ■   Change a database owner by executing system procedures
  4660.  
  4661.    ■   Display information on database ownership
  4662.  
  4663.  ────────────────────────────────────────────────────────────────────────────
  4664.  NOTE
  4665.  
  4666.  The master database is owned by the SA. You cannot change its ownership.
  4667.  ────────────────────────────────────────────────────────────────────────────
  4668.  
  4669.  
  4670.  
  4671.  
  4672.  
  4673.  Changing a Database Owner Using the Admin Menu
  4674.  
  4675.  The SA or Database Owner can use the Admin menu to change database owners.
  4676.  Only the SA and Database Owner have permission to perform this task.
  4677.  
  4678.  To change ownership of a database:
  4679.  
  4680.  
  4681.    1.  Select the Admin menu and choose Change database owner.
  4682.  
  4683.        The "Change Database Owner" dialog box appears.
  4684.  
  4685.    2.  From the "Database" list box, select the database for which you want
  4686.        to change the owner.
  4687.  
  4688.    3.  Choose OK.
  4689.  
  4690.        The "Change Database Owner" dialog box appears. Note that the current
  4691.        Database Owner is listed.
  4692.  
  4693.    4.  In the "New database owner" list box, select the new Database Owner.
  4694.  
  4695.    5.  Choose OK.
  4696.  
  4697.        A message appears:
  4698.  
  4699.        Database owner changed.
  4700.  
  4701.    6.  Choose OK.
  4702.  
  4703.  
  4704.  
  4705.  Changing a Database Owner Using System Procedures
  4706.  
  4707.  To change a database owner in the current database, use the sp_changedbowner
  4708.  system procedure.
  4709.  
  4710.  The new owner must already have a login ID on SQL Server but must not have a
  4711.  database name or alias in the database. If you want to assign database
  4712.  ownership to such a user, drop his or her database name and alias before
  4713.  executing sp_changedbowner.
  4714.  
  4715.  The sp_changedbowner system procedure has the following syntax:
  4716.  
  4717.    sp_changedbowner login_id
  4718.  
  4719.  ────────────────────────────────────────────────────────────────────────────
  4720.  login_id
  4721.    The login ID of the new owner of the current database. The new owner must
  4722.    not already be known as a user or have an alias.
  4723.  
  4724.  ────────────────────────────────────────────────────────────────────────────
  4725.  For example, the SA decides to transfer ownership of the pubs database to
  4726.  Jane. The SA executes these statements:
  4727.  
  4728.    use pubs
  4729.     <execute>
  4730.     sp_changedbowner jane
  4731.  
  4732.  
  4733.  Displaying Information on Database Owners
  4734.  
  4735.  To display information on Database Owners, use the sp_helpuser system
  4736.  procedure (described under "Displaying Information on Usernames," earlier in
  4737.  this chapter.)
  4738.  
  4739.  After you change the Database Owner, the new Database Owner's username shows
  4740.  up as dbo.
  4741.  
  4742.  
  4743.  Displaying Information on Current Users
  4744.  
  4745.  You can display information on current users with the Admin menu, or you can
  4746.  execute a system procedure.
  4747.  
  4748.  To display information on current users using the Admin menu:
  4749.  
  4750.  
  4751.    1.  Select the Admin menu and choose Display current users.
  4752.  
  4753.        The "Display Current Users" dialog box appears. It contains
  4754.        information on all current users of SQL Server.
  4755.  
  4756.    2.  Choose OK.
  4757.  
  4758.  
  4759.  To display information on current users, use the sp_who system procedure.
  4760.  
  4761.  The sp_who system procedure has the following syntax:
  4762.  
  4763.    sp_who
  4764.  
  4765.  The following is a sample report:
  4766.  
  4767. ╓┌───────┌──────────┌──────────┌──────────┌──────────┌───────┌──────────┌────
  4768.  ─────────────────────────────────────────────────────────────────────────────
  4769.  ─────────────────────────────────────────────────────────────────────────────
  4770.          spid       status     loginame   hostname   blk     dbname     cmd
  4771.  
  4772.          ----       --------   --------   --------   ----    -------    ------
  4773.  
  4774.          1          sleeping   sa         plum       0       pubs       AWAITI
  4775.  
  4776.          2          sleeping   sa                    0       master     NETWOR
  4777.  
  4778.          3          sleeping   sa                    0       master     CHECKP
  4779.  
  4780.          4          sleeping   karenp     plum       1       pubs       SELECT
  4781.  
  4782.          5          runnable   karenp     plum       0       pubs       SELECT
  4783.  
  4784.  
  4785.  
  4786.          (5 rows
  4787.          affected)
  4788.  
  4789.  
  4790.  
  4791.  The report headings have the following descriptions:
  4792.  
  4793.  ────────────────────────────────────────────────────────────────────────────
  4794.  spid
  4795.    Server process ID. This number is used in the KILL statement.
  4796.  
  4797.  status
  4798.    Status of the process.
  4799.  
  4800.  loginame
  4801.    Login ID of the process user.
  4802.  
  4803.  hostname
  4804.    Name of workstation.
  4805.  
  4806.  blk
  4807.    Process ID of the blocking process, if there is one.
  4808.  
  4809.  dbname
  4810.    Name of database.
  4811.  
  4812.  cmd
  4813.    Statement name being executed.
  4814.  
  4815.  ────────────────────────────────────────────────────────────────────────────
  4816.  Advanced users may want to query the sysprocesses system table for
  4817.  additional information. See Appendix B, "System Tables," for a description
  4818.  of this table.
  4819.  
  4820.  
  4821.  
  4822.  
  4823.  
  4824.  
  4825.  Chapter 7  Managing User Permissions
  4826.  ────────────────────────────────────────────────────────────────────────────
  4827.  
  4828.  
  4829.  Introduction
  4830.  
  4831.  This chapter describes SQL Server's permissions system. The permissions
  4832.  system specifies which users are authorized to use which SQL statements,
  4833.  views, and stored procedures. The ability to assign permissions is
  4834.  determined by each user's status (as SA, Database Owner, or database object
  4835.  owner).
  4836.  
  4837.  In this chapter, you learn how to
  4838.  
  4839.  
  4840.    ■   Grant and revoke permissions
  4841.  
  4842.    ■   Use views, stored procedures, and triggers
  4843.  
  4844.  
  4845.  
  4846.  Permissions Summary
  4847.  
  4848.  The following table summarizes the SQL Server permissions system. The type
  4849.  of user listed as the one to whom the statement defaults is the "lowest"
  4850.  level of user to which the permission is automatically granted. This user
  4851.  can grant the permission to other users or revoke it from other users, if it
  4852.  is transferable.
  4853.  
  4854.  Table 7.1  Summary of Protection System
  4855.  
  4856. ╓┌────────────┌──────────┌──────────┌──────────┌───────┌──────────┌───┌──────╖
  4857.                                                        Can Be
  4858.               Defaults                                 Granted /
  4859.               to                                       Revoked
  4860.               System     Db Owner   Table      Public  Yes        No  N/A
  4861.               Admin                 Owner
  4862.  Statement:
  4863.  ────────────────────────────────────────────────────────────────────────────
  4864.  ALTER        X          ─          ─          ─       (1)        ─   ─
  4865.  DATABASE
  4866.  
  4867.  ALTER TABLE  ─          ─          X          ─       ─          X   ─
  4868.  
  4869.  BEGIN        ─          ─          ─          X       ─          ─   X
  4870.  TRANSACTION
  4871.  
  4872.  CHECKPOINT   ─          X          ─          ─       ─          X   ─
  4873.  
  4874.                                                        Can Be
  4875.               Defaults                                 Granted /
  4876.               to                                       Revoked
  4877.               System     Db Owner   Table      Public  Yes        No  N/A
  4878.               Admin                 Owner
  4879.  Statement:
  4880. 
  4881.  COMMIT       ─          ─          ─          X       ─          ─   X
  4882.  TRANSACTION
  4883.  
  4884.  CREATE       X          ─          ─          ─       X          ─   ─
  4885.  DATABASE
  4886.  
  4887.  CREATE       ─          X          ─          ─       X          ─   ─
  4888.  DEFAULT
  4889.  
  4890.  CREATE       ─          ─          X          ─       ─          X   ─
  4891.  INDEX
  4892.  
  4893.  CREATE       ─          X          ─          ─       X          ─   ─
  4894.  PROCEDURE
  4895.                                                        Can Be
  4896.               Defaults                                 Granted /
  4897.               to                                       Revoked
  4898.               System     Db Owner   Table      Public  Yes        No  N/A
  4899.               Admin                 Owner
  4900.  Statement:
  4901. PROCEDURE
  4902.  
  4903.  CREATE RULE  ─          X          ─          ─       X          ─   ─
  4904.  
  4905.  CREATE       ─          X          ─          (2)     X(2)       ─   ─
  4906.  TABLE
  4907.  
  4908.  CREATE TRIG  ─          ─          X          ─       ─          X   ─
  4909.  GER
  4910.  
  4911.  CREATE VIEW  ─          X          ─          ─       X          ─   ─
  4912.  
  4913.  DBCC         ─          X          ─          ─       ─          ─   X
  4914.  
  4915.  DELETE       ─          ─          X(3)       ─       X          ─   ─
  4916.                                                        Can Be
  4917.               Defaults                                 Granted /
  4918.               to                                       Revoked
  4919.               System     Db Owner   Table      Public  Yes        No  N/A
  4920.               Admin                 Owner
  4921.  Statement:
  4922. DELETE       ─          ─          X(3)       ─       X          ─   ─
  4923.  
  4924.  DISK INIT    X          ─          ─          ─       ─          X   ─
  4925.  
  4926.  DISK REFIT   X          ─          ─          ─       ─          X   ─
  4927.  
  4928.  DISK REINIT  X          ─          ─          ─       ─          X   ─
  4929.  
  4930.  DROP (any    ─          ─          ─          ─       ─          X   ─
  4931.  object)(4)
  4932.  
  4933.  DUMP         ─          X          ─          ─       X          ─   ─
  4934.  DATABASE
  4935.  
  4936.  DUMP         ─          X          ─          ─       X          ─   ─
  4937.                                                        Can Be
  4938.               Defaults                                 Granted /
  4939.               to                                       Revoked
  4940.               System     Db Owner   Table      Public  Yes        No  N/A
  4941.               Admin                 Owner
  4942.  Statement:
  4943. DUMP         ─          X          ─          ─       X          ─   ─
  4944.  TRANSACTION
  4945.  
  4946.  EXECUTE (5)  ─          ─          ─          ─       X          ─   ─
  4947.  
  4948.  GRANT        ─          X          ─          ─       ─          X   ─
  4949.  
  4950.  GRANT (on    ─          ─          ─          ─       ─          X   ─
  4951.  object) (4)
  4952.  
  4953.  INSERT       ─          ─          X(3)       ─       X          ─   ─
  4954.  
  4955.  KILL         X          ─          ─          ─       ─          X   ─
  4956.  
  4957.  LOAD         ─          X          ─          ─       ─          X   ─
  4958.                                                        Can Be
  4959.               Defaults                                 Granted /
  4960.               to                                       Revoked
  4961.               System     Db Owner   Table      Public  Yes        No  N/A
  4962.               Admin                 Owner
  4963.  Statement:
  4964. LOAD         ─          X          ─          ─       ─          X   ─
  4965.  DATABASE
  4966.  
  4967.  LOAD         ─          X          ─          ─       ─          X   ─
  4968.  TRANSACTION
  4969.  
  4970.  PRINT        ─          ─          ─          X       ─          ─   X
  4971.  
  4972.  RAISERROR    ─          ─          ─          X       ─          ─   X
  4973.  
  4974.  READTEXT     ─          ─          X(3)       ─       X          ─   ─
  4975.  
  4976.  RECONFIGURE  X          ─          ─          ─       ─          X   ─
  4977.  
  4978.  REVOKE       ─          X          ─          ─       ─          X   ─
  4979.                                                        Can Be
  4980.               Defaults                                 Granted /
  4981.               to                                       Revoked
  4982.               System     Db Owner   Table      Public  Yes        No  N/A
  4983.               Admin                 Owner
  4984.  Statement:
  4985. REVOKE       ─          X          ─          ─       ─          X   ─
  4986.  
  4987.  REVOKE (on   ─          ─          ─          ─       ─          X   ─
  4988.  object) (4)
  4989.  
  4990.  ROLLBACK     ─          ─          ─          X       ─          ─   X
  4991.  TRANSACTION
  4992.  
  4993.  SAVE         ─          ─          ─          X       ─          ─   X
  4994.  TRANSACTION
  4995.  
  4996.  SELECT       ─          ─          X(3)       ─       X          ─   ─
  4997.  
  4998.  SET          ─          ─          ─          X       ─          ─   X
  4999.  
  5000.                                                        Can Be
  5001.               Defaults                                 Granted /
  5002.               to                                       Revoked
  5003.               System     Db Owner   Table      Public  Yes        No  N/A
  5004.               Admin                 Owner
  5005.  Statement:
  5006. 
  5007.  SETUSER      ─          X          ─          ─       ─          X   ─
  5008.  
  5009.  TRUNCATE     ─          ─          X          ─       ─          X   ─
  5010.  TABLE
  5011.  
  5012.  UPDATE       ─          ─          X(3)       ─       X          ─   ─
  5013.  
  5014.  UPDATE       ─          ─          X          ─       ─          X   ─
  5015.  STATISTICS
  5016.  
  5017.  WRITETEXT    ─          ─          X(3)       ─       X          ─   ─
  5018.  
  5019.  ────────────────────────────────────────────────────────────────────────────
  5020.  
  5021.                                                        Can Be
  5022.               Defaults                                 Granted /
  5023.               to                                       Revoked
  5024.               System     Db Owner   Table      Public  Yes        No  N/A
  5025.               Admin                 Owner
  5026.  Statement:
  5027. 
  5028.  
  5029.  
  5030.  (1) Transferred with CREATE DATABASE permission
  5031.  (2) Public can create temporary tables, no permission required
  5032.  (3) If a view, permission defaults to view owner
  5033.  (4) Defaults to object owner
  5034.  (5) Defaults to stored procedure owner
  5035.  
  5036.  
  5037.  
  5038.  Object and Statement Permissions
  5039.  
  5040.  There are two categories of permissions: object and statement. Permissions
  5041.  for the SELECT, UPDATE, INSERT, DELETE, and EXECUTE statements are called
  5042.  object permissions because these statements always apply to database objects
  5043.  (in the current database).
  5044.  
  5045.  The objects to which the object permissions apply are as follows:
  5046.  
  5047. ╓┌────────────────────────┌──────────────────────────────────────────────────╖
  5048.  Statement                Object
  5049.  ────────────────────────────────────────────────────────────────────────────
  5050.  SELECT                   Table, view, column
  5051.  UPDATE                   Table, view, column
  5052.  INSERT                   Table, view
  5053.  DELETE                   Table, view
  5054.  EXECUTE                  Stored procedure
  5055.  ────────────────────────────────────────────────────────────────────────────
  5056.  
  5057.  
  5058.  Statement permissions are not object specific. They can be granted only by
  5059.  the SA or a Database Owner. Statement permissions apply to the following
  5060.  statements:
  5061.  
  5062.  
  5063.    ■   CREATE DATABASE (can be granted only by the SA and only to users in
  5064.        the master database)
  5065.  
  5066.    ■   CREATE DEFAULT
  5067.  
  5068.    ■   CREATE PROCEDURE
  5069.  
  5070.    ■   CREATE RULE
  5071.  
  5072.    ■   CREATE TABLE
  5073.  
  5074.    ■   CREATE VIEW
  5075.  
  5076.    ■   DUMP DATABASE
  5077.  
  5078.    ■   DUMP TRANSACTION
  5079.  
  5080.  
  5081.  Each database has its own independent permissions system. In other words,
  5082.  being granted permission to use a certain statement in one database has no
  5083.  effect in other databases.
  5084.  
  5085.  If you try to use a statement or database object for which you do not have
  5086.  permission, SQL Server responds with an error message.
  5087.  
  5088.  
  5089.  The Permission Hierarchy
  5090.  
  5091.  SQL Server's permissions system recognizes four types of users:
  5092.  
  5093.  
  5094.    ■   The SA
  5095.  
  5096.    ■   Database Owners
  5097.  
  5098.    ■   Database object owners
  5099.  
  5100.    ■   Other users of the database
  5101.  
  5102.  
  5103.  The different types of users exist in a kind of hierarchy, with the SA at
  5104.  the top and other users at the bottom.
  5105.  
  5106.  
  5107.  Permissions of the SA
  5108.  
  5109.  The SA is the special user who handles tasks not specific to an application.
  5110.  There are no restrictions on what the SA can do within SQL Server.
  5111.  
  5112.  There are several statements that only the SA can execute; they cannot be
  5113.  granted to any other user:
  5114.  
  5115.  
  5116.    ■   DISK INIT
  5117.  
  5118.    ■   DISK REFIT
  5119.  
  5120.    ■   DISK REINIT
  5121.  
  5122.    ■   KILL
  5123.  
  5124.    ■   RECONFIGURE
  5125.  
  5126.  
  5127.  Only the SA can grant CREATE DATABASE permission. Control of this statement
  5128.  is reserved for the SA because it determines the amount and location of the
  5129.  storage allocated for each database. ALTER DATABASE permission on a database
  5130.  defaults to the owner of that database, but only if he or she has CREATE
  5131.  DATABASE permission. ALTER DATABASE permission cannot be transferred.
  5132.  
  5133.  
  5134.  Permissions of Database Owners
  5135.  
  5136.  The Database Owner has full permission to do anything inside that database
  5137.  and must grant permissions to other users.
  5138.  
  5139.  The following permissions are automatically granted to the Database Owner
  5140.  and cannot be transferred to other users:
  5141.  
  5142.  
  5143.    ■   CHECKPOINT
  5144.  
  5145.    ■   DBCC
  5146.  
  5147.    ■   DROP DATABASE
  5148.  
  5149.    ■   GRANT and REVOKE statement permissions
  5150.  
  5151.    ■   LOAD DATABASE
  5152.  
  5153.    ■   LOAD TRANSACTION
  5154.  
  5155.    ■   SETUSER
  5156.  
  5157.  
  5158.  Database owners can grant permissions on the following statements to other
  5159.  users:
  5160.  
  5161.  
  5162.    ■   CREATE DEFAULT
  5163.  
  5164.    ■   CREATE PROCEDURE
  5165.  
  5166.    ■   CREATE RULE
  5167.  
  5168.    ■   CREATE TABLE
  5169.  
  5170.    ■   CREATE VIEW
  5171.  
  5172.    ■   DUMP DATABASE
  5173.  
  5174.    ■   DUMP TRANSACTION
  5175.  
  5176.    ■   GRANT and REVOKE object permissions
  5177.  
  5178.  
  5179.  
  5180.  Permissions of Database Object Owners
  5181.  
  5182.  A user who creates a database object (a table, view, or stored procedure) is
  5183.  its owner and is automatically granted all object permissions on it. Users
  5184.  other than the object owner, including the owner of the database, are
  5185.  automatically denied all permissions on that object unless they are granted
  5186.  by the owner.
  5187.  
  5188.  Object permissions are granted on the statements SELECT, UPDATE, INSERT,
  5189.  DELETE, and EXECUTE.
  5190.  
  5191.  As an example, say that Mary is the owner of the pubs database and has
  5192.  granted Joe permission to create tables in it. Joe creates the table
  5193.  authors; he is the owner of this database object.
  5194.  
  5195.  Initially, object permissions on authors belong to Joe and Joe alone. Joe
  5196.  can grant object permissions for this table to other users, including Mary,
  5197.  the Database Owner. (However, the Database Owner can use the SETUSER
  5198.  statement to "impersonate" Joe.)
  5199.  
  5200.  The following statement permissions default to the owner of a table and
  5201.  cannot be transferred to other users:
  5202.  
  5203.  
  5204.    ■   ALTER TABLE
  5205.  
  5206.    ■   CREATE INDEX
  5207.  
  5208.    ■   CREATE TRIGGER
  5209.  
  5210.    ■   DROP TABLE
  5211.  
  5212.    ■   TRUNCATE TABLE
  5213.  
  5214.    ■   UPDATE STATISTICS
  5215.  
  5216.  
  5217.  Permission to use the GRANT and REVOKE statements cannot be transferred.
  5218.  
  5219.  Permission to drop an object─a table, view, index, stored procedure, rule,
  5220.  or default─defaults to its owner and cannot be transferred.
  5221.  
  5222.  
  5223.  Permissions on System Tables
  5224.  
  5225.  The SQL Server setup program sets permissions on the system tables in a user
  5226.  database so that all database users can read them.
  5227.  
  5228.  However, the default is that no users─including Database Owners─can modify
  5229.  the system tables directly through SQL statements. Rather, the system tables
  5230.  are modified by executing system procedures or using the SAF menus. (The SA
  5231.  can change this situation so that ad hoc modifications to the system tables
  5232.  are allowed. See Chapter 11, "Diagnosing System Problems," for more
  5233.  information.)
  5234.  
  5235.  
  5236.  Permissions on System Procedures
  5237.  
  5238.  Since system procedures are located in the master database, their
  5239.  permissions are also set there.
  5240.  
  5241.  Some of the system procedures can be executed only by Database Owners. These
  5242.  procedures make sure that the user executing the procedure is the owner of
  5243.  the database from which it is being executed.
  5244.  
  5245.  Other system procedures (for example, all the sp_help procedures) can be
  5246.  executed by any user who has been granted permission─but this permission
  5247.  must be granted in master. In other words, a user must have permission to
  5248.  execute a system procedure in all databases or in none of them.
  5249.  
  5250.  SQL Server users who do not have usernames in the master database are
  5251.  treated as guest in master and thus are automatically granted permission on
  5252.  many of the system procedures. To deny a user permission on a system
  5253.  procedure, the SA must add that user to the master database and write a
  5254.  REVOKE statement that applies to that procedure. The owner of a user
  5255.  database cannot directly control permissions on the system procedures within
  5256.  his or her own database.
  5257.  
  5258.  
  5259.  The SETUSER Statement
  5260.  
  5261.  A Database Owner can use the SETUSER statement to "impersonate" another
  5262.  user's identity and permission status in the current database. A Database
  5263.  Owner can use SETUSER to access an object owned by another user, to grant
  5264.  permissions on an object owned by another user, to create an object that
  5265.  will be owned by another user, or to temporarily take on the permissions of
  5266.  another user.
  5267.  
  5268.  SETUSER permission defaults to the Database Owner and cannot be transferred.
  5269.  The user being impersonated must be an authorized user of the current
  5270.  database.
  5271.  
  5272.  The SETUSER statement has the following syntax:
  5273.  
  5274.    setuser ["user_name"]
  5275.  
  5276.  The SA can use SETUSER to create objects that will be owned by another user.
  5277.  However, since the SA operates outside the permissions system, he or she
  5278.  cannot use SETUSER to acquire another user's permissions. No matter what
  5279.  SETUSER statements have been executed, the SA always retains permission to
  5280.  do everything.
  5281.  
  5282.  To reestablish your original identity, execute the SETUSER statement with no
  5283.  name after it.
  5284.  
  5285.  Here's how the Database Owner would grant Joe permission to read the authors
  5286.  table, which is owned by Mary:
  5287.  
  5288.    setuser "mary"
  5289.     <execute>
  5290.     grant select on authors to joe
  5291.     <execute>
  5292.      setuser
  5293.  
  5294.  When the Database Owner uses the SETUSER statement, SQL Server checks the
  5295.  permissions of the user being impersonated.
  5296.  
  5297.  The SETUSER statement remains in effect until another SETUSER statement is
  5298.  executed or until the current database is changed with the USE statement.
  5299.  
  5300.  
  5301.  Granting and Revoking Permissions
  5302.  
  5303.  Statement and object permissions are granted or removed with the GRANT and
  5304.  REVOKE statements.
  5305.  
  5306.  
  5307.  GRANT and REVOKE Statements
  5308.  
  5309.  The syntax for statement permissions differs slightly from the syntax for
  5310.  object permissions.
  5311.  
  5312.  
  5313.  Statement Permissions
  5314.  
  5315.  Statement permissions have the following syntax:
  5316.  
  5317.    GRANT {ALL | statement_list}
  5318.     TO {PUBLIC | name_list}
  5319.  
  5320.     REVOKE {ALL | statement_list}
  5321.     FROM {PUBLIC | name_list}
  5322.  
  5323.  ────────────────────────────────────────────────────────────────────────────
  5324.  ALL
  5325.    Only the SA can use ALL to assign statement permissions since only the SA
  5326.    can grant or revoke CREATE DATABASE permission.
  5327.  
  5328.  PUBLIC
  5329.    All the users in the public group.
  5330.  
  5331.  statement_list
  5332.    A list of statements granted or revoked. The statement list can include
  5333.    CREATE DATABASE (if the user executing the statement is the SA), CREATE
  5334.    DEFAULT, CREATE PROCEDURE, CREATE RULE, CREATE TABLE, CREATE VIEW, DUMP
  5335.    DATABASE, and DUMP TRANSACTION.
  5336.  
  5337.    If several statements are listed, separate them with commas.
  5338.  
  5339.  name_list
  5340.    A list of users' database names and/or groupnames, separated by commas.
  5341.  
  5342.  ────────────────────────────────────────────────────────────────────────────
  5343.  Object Permissions
  5344.  
  5345.  Object permissions (permission to use tables, views, columns, and stored
  5346.  procedures) have the following syntax:
  5347.  
  5348.    GRANT {ALL | permission_list}
  5349.     ON {table_name [(column_list)...] |
  5350.     view_name [(column_list)] |
  5351.     stored_procedure_name}
  5352.     TO {PUBLIC | name_list}
  5353.  
  5354.     REVOKE {ALL | permission_list}
  5355.     ON {table_name [(column_list...)] |
  5356.     view_name [(column_list)] |
  5357.     stored_procedure_name}
  5358.     FROM {PUBLIC | name_list}
  5359.  
  5360.  ────────────────────────────────────────────────────────────────────────────
  5361.  ALL
  5362.    Specifies that all permissions applicable to the specified object are
  5363.    granted or revoked.
  5364.  
  5365.  permission_list
  5366.    A list of permissions granted or revoked. When permissions are granted or
  5367.    revoked on a table or a view, the permission list can include one or more
  5368.    of the following items: SELECT, INSERT, DELETE, and UPDATE.
  5369.  
  5370.    When permissions are granted or revoked on columns, the permission list
  5371.    can include one or both of the following items: SELECT and UPDATE.
  5372.  
  5373.    When permissions are granted or revoked on stored procedures, the
  5374.    permission list can include EXECUTE only.
  5375.  
  5376.    If several permissions are listed, separate them with commas.
  5377.  
  5378.  table_name
  5379.    The name of one table in the current database.
  5380.  
  5381.  column_list
  5382.    A list of columns, separated by commas, to which the permissions apply. If
  5383.    columns are specified, only SELECT and UPDATE permissions can be granted.
  5384.    If several columns are specified, all columns must be in the same table or
  5385.    view.
  5386.  
  5387.  view_name
  5388.    The name of one view in the current database.
  5389.  
  5390.  stored_procedure_name
  5391.    The name of one stored procedure in the current database.
  5392.  
  5393.  PUBLIC
  5394.    All users in the public group.
  5395.  
  5396.  name_list
  5397.    A list of users' database names and/or groupnames, separated by commas.
  5398.  
  5399.  ────────────────────────────────────────────────────────────────────────────
  5400.  Examples
  5401.  
  5402.  The following statement grants permission to mary and the sales group to
  5403.  insert into and delete from the titles table:
  5404.  
  5405.    grant insert, delete
  5406.     on titles
  5407.     to mary, sales
  5408.  
  5409.  The following statement grants permission to harold to use the makelist
  5410.  stored procedure:
  5411.  
  5412.    grant execute
  5413.     on makelist
  5414.     to harold
  5415.  
  5416.  The following statement revokes permission from all users to update the
  5417.  price and ytd_sales columns of the titles table:
  5418.  
  5419.    revoke update
  5420.     on titles (price, ytd_sales)
  5421.     from public
  5422.  
  5423.  The following examples show how to grant and revoke statement permissions:
  5424.  
  5425.    grant create table, create view
  5426.     to mary, jane, bob
  5427.  
  5428.     grant dump database, dump tran
  5429.     to public
  5430.  
  5431.     revoke create table, create rule
  5432.     from mary
  5433.  
  5434.  
  5435.  Combining GRANT and REVOKE Statements
  5436.  
  5437.  There are two basic ways of setting up permissions in a database or on a
  5438.  database object. The most straightforward way is to assign specific
  5439.  permissions to specific users.
  5440.  
  5441.  However, if most users are going to be granted most permissions, it's easier
  5442.  to assign all permissions to all users and then revoke specific permissions
  5443.  from specific users.
  5444.  
  5445.  For example, a Database Owner can grant all permissions on the titles table
  5446.  to all users by executing the following statement:
  5447.  
  5448.    grant all
  5449.     on titles
  5450.     to public
  5451.  
  5452.  Then the Database Owner can execute a series of REVOKE statements to remove
  5453.  permissions; for example:
  5454.  
  5455.    revoke update
  5456.     on titles (royalty, advance)
  5457.     from public
  5458.  
  5459.     revoke delete
  5460.     on titles
  5461.     from mary, sales, john
  5462.  
  5463.  
  5464.  Conflicting GRANT and REVOKE Statements
  5465.  
  5466.  As implied in the preceding section, GRANT and REVOKE statements are
  5467.  sensitive to the order in which they are executed. So, for example, if Joe's
  5468.  group has been granted select permission on the titles table and then Joe's
  5469.  permission to select the advance column has been revoked, Joe can select all
  5470.  the columns except advance, while the other users in his group can still
  5471.  select all the columns.
  5472.  
  5473.  A GRANT or REVOKE statement that applies to a group changes any conflicting
  5474.  permissions that have been assigned to any member of that group. For
  5475.  example, the owner of the titles table has granted different permissions to
  5476.  various members of the sales group and then decides to standardize. The
  5477.  owner might execute the following statements:
  5478.  
  5479.    revoke all on titles from sales
  5480.     grant select on titles(title, title_id, type, pub_id) to sales
  5481.  
  5482.  Similarly, a GRANT or REVOKE statement executed for public will change, for
  5483.  all users in the public group, any previously executed permissions that
  5484.  conflict with the new statement.
  5485.  
  5486.  The same GRANT and REVOKE statements executed in different order can create
  5487.  entirely different situations. For example, following is a set of statements
  5488.  that leaves Joe without any select permission on titles (assuming Joe
  5489.  belongs to the public group):
  5490.  
  5491.    grant select on titles(title_id, title) to joe
  5492.     revoke select on titles from public
  5493.  
  5494.  In contrast, the same statements executed in the opposite order result in
  5495.  only Joe having select permission, and only on the title_id and title
  5496.  columns.
  5497.  
  5498.  Remember that when you use the PUBLIC keyword, you are including yourself
  5499.  (if you are a member of the public group). You may want to deny yourself
  5500.  permission to use your own table, while giving yourself permission to access
  5501.  a view built on it. (You can always change your mind and reinstitute the
  5502.  permission with a GRANT statement.) You will probably use PUBLIC more
  5503.  frequently as a quick way of revoking permissions and then defining some
  5504.  exceptions, as in the earlier example.
  5505.  
  5506.  
  5507.  Displaying Information on Permissions
  5508.  
  5509.  The sp_helprotect system procedure reports on permissions by database object
  5510.  and (optionally) by user for the specified object. Any user can execute this
  5511.  procedure.
  5512.  
  5513.  The sp_helprotect system procedure has the following syntax:
  5514.  
  5515.    sp_helprotect name [, user_name]
  5516.  
  5517.  ────────────────────────────────────────────────────────────────────────────
  5518.  name
  5519.    The name of a table, view, or stored procedure; or the name of a user or
  5520.    group in the current database.
  5521.  
  5522.  user_name
  5523.    A user's name in the current database.
  5524.  
  5525.  ────────────────────────────────────────────────────────────────────────────
  5526.  The following is a series of GRANT and REVOKE statements:
  5527.  
  5528.    grant select on titles to judy
  5529.     grant update on titles to judy
  5530.     revoke update on titles(price) from judy
  5531.  
  5532.  Here is the display that would be generated after executing the GRANT and
  5533.  REVOKE statements:
  5534.  
  5535.    sp_helprotect titles
  5536.  
  5537.     type   action   user   column
  5538.     ---------  ---------  ---------  ---------
  5539.     Grant   Select   public   All
  5540.     Grant   Select   guest   All
  5541.     Grant   Update   guest   All
  5542.     Grant   Select   judy   All
  5543.     Grant   Update   judy   title_id
  5544.     Grant   Update   judy   title
  5545.     Grant   Update   judy   type
  5546.     Grant   Update   judy   pub_id
  5547.     Grant   Update   judy   advance
  5548.     Grant   Update   judy   royalty
  5549.     Grant   Update   judy   notes
  5550.     Revoke   Update   judy   price
  5551.  
  5552.     (12 rows affected)
  5553.  
  5554.  
  5555.  Permissions on Views and Stored Procedures
  5556.  
  5557.  Views and stored procedures can serve as security mechanisms. A user can be
  5558.  granted permission on a view or on a stored procedure even if he or she has
  5559.  no permissions on objects the view or procedure references.
  5560.  
  5561.  
  5562.  Views as Security Mechanisms
  5563.  
  5564.  Through a view, users can query and modify only the data they can see. The
  5565.  rest of the database is neither visible nor accessible.
  5566.  
  5567.  Permission to access the subset of data in a view must be granted or
  5568.  revoked, regardless of the set of permissions in force on the view's
  5569.  underlying tables. Data in an underlying table that is not included in the
  5570.  view is hidden from users who are authorized to access the view but not the
  5571.  underlying table.
  5572.  
  5573.  By defining different views and selectively granting permissions on them, a
  5574.  user (or any combination of users) can be restricted to different subsets of
  5575.  data. The following examples illustrate the use of views for security
  5576.  purposes:
  5577.  
  5578.  
  5579.    ■   Access can be restricted to a subset of the rows of a base table (a
  5580.        value-dependent subset). For example, you might define a view that
  5581.        contains only the rows for business and psychology books to keep
  5582.        information about other types of books hidden from some users.
  5583.  
  5584.    ■   Access can be restricted to a subset of the columns of a base table (a
  5585.        value-independent subset). For example, you might define a view that
  5586.        contains all the rows of the titles table but omits the royalty and
  5587.        advance columns, since this information is sensitive.
  5588.  
  5589.    ■   Access can be restricted to a row-and-column subset of a base table.
  5590.  
  5591.    ■   Access can be restricted to the rows that qualify for a join of more
  5592.        than one base table. For example, you might define a view that joins
  5593.        the titles, authors, and titleauthor table to display the names of the
  5594.        authors and the books they have written. This view would hide personal
  5595.        data about authors and financial information about the books.
  5596.  
  5597.    ■   Access can be restricted to a statistical summary of data in a base
  5598.        table. For example, you might define a view that contains only the
  5599.        average price of each type of book.
  5600.  
  5601.    ■   Access can be restricted to a subset of another view or of some
  5602.        combination of views and base tables.
  5603.  
  5604.  
  5605.  As an example, you want to prevent some users from accessing the columns in
  5606.  the titles table that have to do with money and sales. You could create a
  5607.  view of the titles table that omits those columns and then give all users
  5608.  permission on the view but only the Sales Department permission on the
  5609.  table. You would execute the following statements:
  5610.  
  5611.    grant all on bookview to public
  5612.     grant all on titles to sales
  5613.  
  5614.  An equivalent way of setting up these permission conditions without using a
  5615.  view is this series of statements:
  5616.  
  5617.    grant all on titles to public
  5618.     revoke select, update on titles (price, advance, royalty, ytd_sales)
  5619.      from public
  5620.     grant select, update on titles (price, advance, royalty, ytd_sales)
  5621.      to sales
  5622.  
  5623.  One possible problem with the second scheme is that users not in the sales
  5624.  group who enter the statement "SELECT * from titles" might be surprised to
  5625.  see a "permission denied" message. SQL Server expands the asterisk into a
  5626.  list of all the columns in the titles table and since permission on some of
  5627.  these columns has been revoked from nonsales users, refuses access to them.
  5628.  The error message lists the columns for which the user does not have access.
  5629.  
  5630.  
  5631.  To see all the columns for which they do have permission, the nonsales users
  5632.  would have to name them specifically. For this reason, creating a view and
  5633.  granting the appropriate permissions on it is a better solution.
  5634.  
  5635.  In addition to protecting data based on a selection of rows and/or columns,
  5636.  views can be used for context-sensitive permission. For example, you can
  5637.  create a view that gives a data entry clerk permission to access only those
  5638.  rows that he or she has added or updated.
  5639.  
  5640.  To do so, you would add a uid column to a table in which the user ID of the
  5641.  user entering each row is automatically recorded with a default. Define the
  5642.  default using the user_id system function and bind it to uid, like this:
  5643.  
  5644.    create default user_def
  5645.     as user_id()
  5646.  
  5647.     sp_bindefault user_def, "testtable.uid"
  5648.  
  5649.  Next, define a view that includes all the rows of the table where uid is the
  5650.  current user:
  5651.  
  5652.    create view context_view
  5653.     as select *
  5654.     from testtable
  5655.     where uid = user_id()
  5656.  
  5657.  The rows retrievable through this view depend on the identity of the person
  5658.  who executes the SELECT statement against the view. For more information on
  5659.  creating views, see SQL Server Learning TRANSACT-SQL.
  5660.  
  5661.  Permissions on views are checked when the view is used, not when it is
  5662.  created.
  5663.  
  5664.  
  5665.  Stored Procedures as Security Mechanisms
  5666.  
  5667.  A user with permission to execute a stored procedure can do so even if he or
  5668.  she does not have permissions on tables or views referenced in it. For
  5669.  example, a user might be given permission to execute a stored procedure that
  5670.  updates a row-and-column subset of a specified table even though that user
  5671.  does not have any other permissions on that table.
  5672.  
  5673.  Permissions on stored procedures are checked when the procedure is used, not
  5674.  when it is created.
  5675.  
  5676.  
  5677.  Ownership Chains
  5678.  
  5679.  Views can depend on other views and/or tables. Procedures can depend on
  5680.  other procedures, views, and/or tables. These dependencies can be thought of
  5681.  as an "ownership chain."
  5682.  
  5683.  Typically, the owner of a view also owns its underlying objects (other views
  5684.  and tables), and the owner of a stored procedure often owns all the
  5685.  procedures, tables, and views the procedure references. Also, a view and its
  5686.  underlying objects are usually all in the same database, as are a stored
  5687.  procedure and all the objects it references.
  5688.  
  5689.  When a user with permission to access a view does so, SQL Server does not
  5690.  check permissions on any of the view's underlying objects if these objects
  5691.  and the view are all owned by the same user, and if the view and all its
  5692.  underlying objects are in the same database.
  5693.  
  5694.  Similarly, if the same user owns a stored procedure and all the views or
  5695.  tables it references, and if the procedure and the objects it references are
  5696.  all in the same database, SQL Server checks only the permissions on the
  5697.  procedure.
  5698.  
  5699.  However, if the ownership chain of a procedure or view is broken─that is, if
  5700.  not all the objects in the chain are owned by the same user─SQL Server
  5701.  checks permissions on each object in the chain whose next lower "link" is
  5702.  owned by a different user. In this way, SQL Server allows the owner of the
  5703.  original data to retain control over who is authorized to access it.
  5704.  
  5705.  Ordinarily, a user who creates a view only has to grant permissions on that
  5706.  view. For example, say Mary has created a view called auview1 on the authors
  5707.  table, which she also owns. If Mary grants Sue permission to use auview1,
  5708.  SQL Server will let Sue access it without checking permissions on authors.
  5709.  
  5710.  However, a user who creates a view or stored procedure that depends on an
  5711.  object owned by another user must be aware that any permissions he or she
  5712.  grants depend on the permissions allowed by those other owners.
  5713.  
  5714.  For example, Joe creates a view called auview2, which depends on Mary's view
  5715.  auview1. Joe grants Sue permission to use auview2:
  5716.  
  5717.    auview2(Joe) --> auview1(Mary) --> authors(Mary)
  5718.  
  5719.  SQL Server checks the permissions on auview2 and auview1, and finds that Sue
  5720.  is allowed to use them.
  5721.  
  5722.  SQL Server performs no authorization checks at the time the view is created.
  5723.  In fact, if Joe has permission on the CREATE VIEW statement, he can define a
  5724.  view based on the authors table even if he does not have SELECT permission
  5725.  on authors. However, the view would be useless to everyone, including Joe.
  5726.  
  5727.  Let's take our example a step further. Suppose that Joe's view, auview2,
  5728.  depends on auview1, which depends on authors. Mary decides she likes Joe's
  5729.  auview2 and creates auview3 on top of it. As you may recall, both auview1
  5730.  and authors are owned by Mary. The situation can be depicted like this, with
  5731.  the object owner given in parentheses after the object name:
  5732.  
  5733.    auview3(Mary) --> auview2(Joe) --> auview1(Mary) --> authors(Mary)
  5734.  
  5735.  When Sue tries to access auview3, SQL Server checks permissions on auview3,
  5736.  auview2, and auview1. If Joe has granted Sue access on auview2 and Mary has
  5737.  granted her permission on auview3 and auview1, SQL Server allows the access.
  5738.  SQL Server checks permissions only if the object immediately before it in
  5739.  the chain has a different owner (or if it is the first object in the chain).
  5740.  For example, it checks auview2 because the object before it─auview3─is owned
  5741.  by a different user. It does not check permission on authors because the
  5742.  object whic
  5743.  
  5744.  (Please refer to the printed book.)
  5745.  
  5746.  h immediately depends on it, auview1, is owned by the same user.  Procedures
  5747.  follow the same rules. As an example, suppose the situation is this:
  5748.  
  5749.    P4(Mary) --> P3(Mary) --> P2(Joe) --> P1(Mary) --> authors(Mary)
  5750.  
  5751.  To execute P4, Sue must have permission to execute P4, P2, and P1.
  5752.  Permission to execute P3 is not necessary, since P3 and P4 have the same
  5753.  owner.
  5754.  
  5755.  SQL Server checks Sue's permissions on P4 and all objects it references each
  5756.  time she executes P4. However, SQL Server knows which referenced objects to
  5757.  check because it has determined this the first time Sue executes P4 and has
  5758.  saved this information with the procedure's execution plan. Unless one of
  5759.  the objects referenced by the procedure is dropped or otherwise redefined,
  5760.  SQL Server sticks with its initial decision about which objects to check.
  5761.  
  5762.  Figure 7.1 shows a situation in which procedures and views owned by two
  5763.  different users depend on each other in a fairly complex way.
  5764.  
  5765.  (This figure may be found in the printed book.)
  5766.  
  5767.  If a user tries to execute procedure1, SQL Server checks permissions on
  5768.  procedure1, procedure3, view2, table2, and table3.
  5769.  
  5770.  In summary, the purpose of this permission hierarchy is to allow every
  5771.  object's owner to fully control access to the object. Owners can control
  5772.  access to views and stored procedures, as well as to tables.
  5773.  
  5774.  
  5775.  Triggers
  5776.  
  5777.  Triggers are a special kind of stored procedure used to enforce integrity,
  5778.  especially referential integrity. (See SQL Server Learning TRANSACT-SQL or
  5779.  the SQL Server Language Reference for details.) Triggers are never executed
  5780.  directly, but only as a side effect of modifying a table. There is no way to
  5781.  grant or revoke permissions for triggers.
  5782.  
  5783.  Only the owner of an object can create a trigger on it. However, the
  5784.  ownership chain can be broken if a trigger on a table references objects
  5785.  owned by different users. The permission hierarchy rules that apply to
  5786.  procedures also apply to triggers.
  5787.  
  5788.  While the objects that a trigger affects are usually owned by the same user
  5789.  who owns the trigger, you can write a trigger that modifies an object owned
  5790.  by another user. If this is the case, any users modifying your object in a
  5791.  way that kicks off the trigger must have permission on the other object as
  5792.  well.
  5793.  
  5794.  If SQL Server denies permission on a data modification statement because of
  5795.  a trigger that affects an object for which the user does not have
  5796.  permission, the entire data modification statement is aborted.
  5797.  
  5798.  
  5799.  
  5800.  
  5801.  
  5802.  
  5803.  Chapter 8  Backup and Recovery
  5804.  ────────────────────────────────────────────────────────────────────────────
  5805.  
  5806.  
  5807.  Introduction
  5808.  
  5809.  SQL Server provides two different kinds of recovery: one that is done
  5810.  automatically and one that you are responsible for doing.
  5811.  
  5812.  Automatic recovery is run every time SQL Server is restarted. This type of
  5813.  recovery protects you from system failures.
  5814.  
  5815.  For the nonautomatic type of recovery, you dump the database at regular
  5816.  intervals and then load the dumped database when necessary. This type of
  5817.  recovery is the only means of recovering data in case of media failure.
  5818.  
  5819.  This chapter describes automatic recovery and how to
  5820.  
  5821.  
  5822.    ■   Dump databases and transaction logs
  5823.  
  5824.    ■   Load databases
  5825.  
  5826.    ■   Load transaction logs
  5827.  
  5828.    ■   Move databases
  5829.  
  5830.    ■   Restore the master database
  5831.  
  5832.    ■   Recover from media failure
  5833.  
  5834.  
  5835.  
  5836.  Automatic Recovery
  5837.  
  5838.  Whenever SQL Server is restarted, recovery is performed automatically on
  5839.  each database. Typically, recovery takes from a few seconds to a few
  5840.  minutes.
  5841.  
  5842.  Automatic recovery does the following:
  5843.  
  5844.  
  5845.    1.  Rolls back uncommitted transactions─those that were ongoing at the
  5846.        time of the failure.
  5847.  
  5848.    2.  Checks the transactions that had been committed between the last
  5849.        checkpoint and the failure, and rolls them forward.
  5850.  
  5851.  
  5852.  Automatic recovery begins with the master database, goes on to model, clears
  5853.  out the tempdb temporary database, and finally recovers user databases.
  5854.  Users can log in to SQL Server as soon as the system databases have been
  5855.  recovered but can't access other databases while recovery is in progress.
  5856.  
  5857.  Two configuration options are relevant to automatic recovery:
  5858.  
  5859.  
  5860.    ■   The recovery interval option controls the maximum time required to
  5861.        recover a database by setting the interval at which SQL Server decides
  5862.        whether to run an automatic checkpoint.
  5863.  
  5864.    ■   The recovery flags option determines what information SQL Server
  5865.        displays during recovery.
  5866.  
  5867.  
  5868.  For more information on configuration options, see Chapter 9, "Fine-tuning
  5869.  Performance and Operations."
  5870.  
  5871.  In each database, the automatic recovery mechanism looks at the transaction
  5872.  log. If the log has been written more recently than the database, the
  5873.  recovery mechanism rolls the committed transactions forward so that the
  5874.  database looks like the log. However, if the transactions were not
  5875.  committed, it rolls them back.
  5876.  
  5877.  
  5878.  Transaction Logs
  5879.  
  5880.  Unless you specify otherwise, every change to a database is automatically
  5881.  recorded in its transaction log. Each database has its own transaction log.
  5882.  The transaction log is used by SQL Server during automatic recovery and is
  5883.  not queried with SQL statements.
  5884.  
  5885.  The transaction log records data modification requests (UPDATE, INSERT, or
  5886.  DELETE statements) as they are executed. When a transaction begins, a "begin
  5887.  transaction" event is recorded in the log. This event is used during
  5888.  automatic recovery to determine the starting point of the transaction.
  5889.  
  5890.  As each data modification statement is received, it is recorded in the log.
  5891.  The change is always recorded in the log before that change is made in the
  5892.  database itself. This type of log is called a write-ahead log. (Before the
  5893.  database or log changes are written to the database device, they are in the
  5894.  disk cache in memory.)
  5895.  
  5896.  The transaction log is shared by all users of the database so that multiple
  5897.  changes are frequently recorded each time a log page is written to the
  5898.  database device.
  5899.  
  5900.  ────────────────────────────────────────────────────────────────────────────
  5901.  WARNING
  5902.  
  5903.  Do not access the syslogs system table. It is for the internal use of SQL
  5904.  Server only.
  5905.  ────────────────────────────────────────────────────────────────────────────
  5906.  
  5907.  
  5908.  Checkpoints
  5909.  
  5910.  The checkpoint mechanism is an automatic means of guaranteeing that
  5911.  completed transactions are regularly written from the disk cache to the
  5912.  database device. A checkpoint writes all "dirty" pages─pages that have been
  5913.  modified since the last checkpoint─to the database device.
  5914.  
  5915.  There are two kinds of checkpoints: those executed automatically by SQL
  5916.  Server and those "forced" by Database Owners with the CHECKPOINT statement.
  5917.  
  5918.  
  5919.  Forcing the dirty pages onto the database device means that all completed
  5920.  transactions are written out. By calling all completed transactions to be
  5921.  written out, the checkpoint shortens the time it takes to recover. A typical
  5922.  checkpoint takes about a second.
  5923.  
  5924.  The automatic checkpoint interval is calculated by SQL Server on the basis
  5925.  of system activity and the recovery interval configuration option, which
  5926.  specifies the maximum acceptable recovery time. For more information on
  5927.  configuration options, see Chapter 9, "Fine-tuning Performance and
  5928.  Operations."
  5929.  
  5930.  The checkpoint (actually, the checkpoint checking process) also performs a
  5931.  few other "housekeeping" tasks, including truncating the log if this
  5932.  database option has been set. For more information on database options, see
  5933.  Chapter 9, "Fine-tuning Performance and Operations."
  5934.  
  5935.  Database Owners can force a checkpoint at any time by executing the
  5936.  CHECKPOINT statement:
  5937.  
  5938.    checkpoint
  5939.  
  5940.  Permission to execute the CHECKPOINT statement defaults to the Database
  5941.  Owner and cannot be transferred to other users.
  5942.  
  5943.  The CHECKPOINT statement applies to the current database. Like the automatic
  5944.  checkpoint, it forces all dirty pages in the database to be written to disk.
  5945.  
  5946.  
  5947.  The CHECKPOINT statement is used in the following ways:
  5948.  
  5949.  
  5950.    ■   As a precautionary measure in special circumstances─for example, just
  5951.        before a planned restart so that SQL Server's recovery mechanisms
  5952.        won't have anything to recover.
  5953.  
  5954.    ■   To cause a change in database options to take effect after the
  5955.        database options have been reset. (See Chapter 9, "Fine-tuning
  5956.        Performance and Operations.")
  5957.  
  5958.    ■   To make a ROLLBACK TRANSACTION statement take effect when aborting a
  5959.        user-defined transaction in which a database option was changed.
  5960.  
  5961.  
  5962.  
  5963.  Dumping a Database or Transaction Log
  5964.  
  5965.  In case of media failure, you can recover your databases if you have been
  5966.  making regular backups of your databases and their transaction logs. These
  5967.  nonautomatic recovery mechanisms depend completely on the regular use of
  5968.  database dumps.
  5969.  
  5970.  Backup responsibility is usually assigned either to the SA or Database
  5971.  Owner. However, permission to dump a database or transaction log can be
  5972.  transferred by the Database Owner to other users. In any case, the user
  5973.  responsible should set up a regular backup schedule.
  5974.  
  5975.  There is no "best" schedule for backing up databases and transaction logs,
  5976.  but keep in mind that the frequency of your backups determines the largest
  5977.  amount of work that could possibly be lost if a media failure should occur.
  5978.  At installations with large and active databases, daily backups of the
  5979.  transaction log and weekly database backups are typical.
  5980.  
  5981.  You can dump a database or a transaction log while the database is active.
  5982.  This type of backup is known as a dynamic dump. The dynamic dump makes
  5983.  backups convenient and continuous operation possible.
  5984.  
  5985.  The dynamic dump slows SQL Server somewhat; you should execute it only when
  5986.  the database is not being heavily updated.
  5987.  
  5988.  ────────────────────────────────────────────────────────────────────────────
  5989.  WARNING
  5990.  
  5991.  Do not use an MS-DOS workstation when you are backing up a database or
  5992.  transaction log to diskettes. (Since the console utility program is not
  5993.  available under MS-DOS, you must use an MS OS/2 server or workstation to
  5994.  perform diskette backups.)
  5995.  ────────────────────────────────────────────────────────────────────────────
  5996.  
  5997.  As explained in Chapter 5, "Managing Storage," the SA is responsible for
  5998.  maintaining the transaction log. These are the steps involved:
  5999.  
  6000.  
  6001.    ■   Putting the transaction log into a separate database device. This is
  6002.        recommended for all databases and especially for databases larger than
  6003.        4 megabytes.
  6004.  
  6005.    ■   Monitoring the transaction log with the sp_spaceused and sp_helpdb
  6006.        system procedures.
  6007.  
  6008.    ■   Keeping the transaction log at a reasonable size by regularly dumping
  6009.        (when the log is in a separate database device).
  6010.  
  6011.  
  6012.  The DUMP DATABASE statement executes a checkpoint internally. This forces
  6013.  all completed transactions to be written out. It then makes an exact image
  6014.  of the database, capturing it as it was the moment the DUMP statement was
  6015.  executed.
  6016.  
  6017.  However, any transactions that were not committed at the start of the dump
  6018.  will not appear in the database should it be subsequently loaded. Any
  6019.  changes made after the dump begins are not reflected in the image. Only
  6020.  pages containing data are dumped.
  6021.  
  6022.  While the dump is in progress, a change to a data or index page that has
  6023.  already been dumped has no effect on the dumped image and takes place
  6024.  immediately. If an update is requested on a page that has not yet been
  6025.  dumped, the system immediately dumps that page and only then makes the
  6026.  change. In other words, users writing a page during a dump have to wait for
  6027.  the dump to write the page first.
  6028.  
  6029.  Remember that each dump of a database or a transaction log overwrites the
  6030.  current contents of the disk or diskette dump device.
  6031.  
  6032.  The procedures described in the following sections apply to dumping both
  6033.  user databases and the master database. Reloading the master database is a
  6034.  special case that is discussed later in this chapter.
  6035.  
  6036.  
  6037.  When to Dump Databases
  6038.  
  6039.  It is recommended that you dump databases and transaction logs frequently
  6040.  and that you save the diskettes containing those dumps.
  6041.  
  6042.  The frequency of your dumps and the amount of time you should save the dump
  6043.  diskettes depend on your database application. As an example, a typical
  6044.  schedule is shown below:
  6045.  
  6046.  When to Perform          What to Dump             Minimum Time to Keep
  6047.  the Dump                 to Diskette              Dump Diskettes
  6048.  ────────────────────────────────────────────────────────────────────────────
  6049.  Every day                Transaction log          Two weeks
  6050.  
  6051.  Every week               Database and             Two months
  6052.                           transaction log
  6053.  
  6054.  Every month              Database and             Six months
  6055.                           transaction log
  6056.  
  6057.  ────────────────────────────────────────────────────────────────────────────
  6058.  
  6059.  
  6060.  
  6061.  Dump Devices
  6062.  
  6063.  Dump devices are hard disk files or diskette files to which you dump
  6064.  databases. You can display a listing of all dump devices by executing the
  6065.  sp_helpdevice system procedure.
  6066.  
  6067.  In the report you get from sp_helpdevice, the ctrltype column shows the type
  6068.  of dump device. You can execute more than one dump at the same time, but
  6069.  only if you are dumping to devices with different cntrltypes.
  6070.  
  6071.  For instructions on how to add dump devices, refer to Chapter 5, "Managing
  6072.  Storage."
  6073.  
  6074.  
  6075.  Disk Dump Devices
  6076.  
  6077.  Disk dump devices are hard disk files. Dumping to a file on the same
  6078.  physical device as the database is not usually recommended; if the disk
  6079.  containing that file crashes, there is no way to recover the database.
  6080.  (However, you may want to dump to a hard disk file and then copy that file
  6081.  to a different medium, such as tape.) When dumping to a hard disk file, any
  6082.  existing contents of the file are overwritten.
  6083.  
  6084.  Only one dump or load to a disk dump device can be active at a time.
  6085.  
  6086.  
  6087.  Diskette Dump Devices
  6088.  
  6089.  Diskettes are suitable as dump devices since they permit a library of
  6090.  database and transaction log dumps to be kept off-line. A database can span
  6091.  several diskettes.
  6092.  
  6093.  The SAF or the console program is used to prompt you when a diskette is used
  6094.  as a dump device.
  6095.  
  6096.  Diskette dump devices must be located on the computer where SQL Server is
  6097.  running. That is, a diskette drive must be physically attached to that
  6098.  machine, and a dump device must be accessible on that machine.
  6099.  
  6100.  You cannot simultaneously dump multiple databases to the same diskette, but
  6101.  you can execute more than one dump or load at the same time to two diskette
  6102.  dump devices (assuming that the diskette dump devices have different
  6103.  controller numbers). You can execute sp_helpdevice to find diskette dump
  6104.  device controller numbers.
  6105.  
  6106.  
  6107.  Dumping a Database
  6108.  
  6109.  Dumping a database backs up an entire database─its system tables,
  6110.  user-defined objects, and transaction log (if the transaction log is in the
  6111.  same database device).
  6112.  
  6113.  When you dump a small database (less than 4 megabytes) that stores its
  6114.  transaction log on the same database device as the rest of the database, you
  6115.  back up both the database and the transaction log at the same time.
  6116.  
  6117.  With a larger database where you store the transaction log on a different
  6118.  database device than the one containing the rest of the database, you will
  6119.  probably want to back up the transaction log more frequently than you back
  6120.  up the database to capture changes made since the last database dump.
  6121.  Dumping the transaction log is discussed in "Dumping a Transaction Log,"
  6122.  later in this chapter. See Chapter 5, "Managing Storage," for more
  6123.  information.
  6124.  
  6125.  
  6126.  When to Dump a Database
  6127.  
  6128.  In addition to routine backups, it is important to dump a database at other
  6129.  times, as described in the following sections.
  6130.  
  6131.  
  6132.  After Creating a Database
  6133.  
  6134.  Each database should be dumped just after it is created to provide a base
  6135.  point, and on a fixed schedule thereafter. If, for example, you create a
  6136.  database on Monday and wait until the weekly Friday afternoon backup time to
  6137.  dump it, you risk losing a whole week's work if there's a media failure on
  6138.  Friday at noon. Transaction log dumps made between the creation of the
  6139.  database and the first database dump are of no use, since you must load them
  6140.  after having loaded a database dump.
  6141.  
  6142.  
  6143.  After Performing a Nonlogged Operation
  6144.  
  6145.  In addition to dumping each database on a fixed schedule, you must dump a
  6146.  database any time you perform an operation that is not logged. For example,
  6147.  dump a database
  6148.  
  6149.  
  6150.    ■   Every time you are forced to execute DUMP TRANSACTION WITH NO_LOG
  6151.        (because you've run out of disk space in the database).
  6152.  
  6153.    ■   Every time you enable the select into/bulkcopy option and do a "fast"
  6154.        bulk copy, or use the SELECT INTO statement to create a permanent
  6155.        table, or use the WRITETEXT statement.
  6156.  
  6157.    ■   Every time you use WRITETEXT, SELECT INTO on a permanent table, and
  6158.        "fast" bulk copy (because SQL Server does not log the data insertions
  6159.        made by these statements, there would be no way to recover them in
  6160.        case of media failure).
  6161.  
  6162.  
  6163.  
  6164.  After Creating an Index
  6165.  
  6166.  It is wise to dump the database each time you create a new index. The pages
  6167.  that are written when a new index is created are not recorded in the log;
  6168.  instead SQL Server relies on LOAD TRANSACTION to re-create the index in case
  6169.  of media failure. This does not mean that CREATE INDEX is unrecoverable, but
  6170.  that SQL Server takes just as long to recover the index as to create it in
  6171.  the first place. Since you will be using LOAD TRANSACTION after a media
  6172.  disaster, when time is likely to be of the essence, it is far better to have
  6173.  dumped the database so that you don't have to wait for the index to be
  6174.  rebuilt.
  6175.  
  6176.  
  6177.  When to Dump the master Database
  6178.  
  6179.  The master database is backed up in the same way as user databases and
  6180.  should be dumped regularly and frequently. It is important to make backups
  6181.  of master after each CREATE DATABASE, ALTER DATABASE, or DISK INIT statement
  6182.  is executed.
  6183.  
  6184.  The backups of the master database are used as part of the recovery
  6185.  procedure in case of a failure that affects the master database. If the
  6186.  master database is damaged, it is recovered differently than user databases.
  6187.  See "Restoring the master Database," later in this chapter.
  6188.  
  6189.  
  6190.  Dumping a Database Using the Admin Menu
  6191.  
  6192.  The procedure for dumping a database is slightly different depending on
  6193.  whether you are dumping to diskettes or to a hard disk.
  6194.  
  6195.  To dump a database:
  6196.  
  6197.  
  6198.    1.  If you are dumping to diskettes, make sure that you have enough
  6199.        formatted diskettes.
  6200.  
  6201.    2.  Select the Admin menu and choose Backup.
  6202.  
  6203.        The "Backup (Dump) Database" dialog box appears.
  6204.  
  6205.    3.  Select "Database".
  6206.  
  6207.    4.  Select the name of the database to be backed up from the "Database
  6208.        name" list box.
  6209.  
  6210.    5.  Select the name of the dump device to which the database will be
  6211.        backed up from the "Dump device" list box.
  6212.  
  6213.    6.  Choose OK.
  6214.  
  6215.    7.  If you are dumping the database to a diskette, follow the directions
  6216.        on the screen. These directions tell you when to insert diskettes.
  6217.  
  6218.        If you are dumping the database to a hard disk, the dump begins
  6219.        immediately.
  6220.  
  6221.  
  6222.  
  6223.  Dumping a Database Using System Procedures
  6224.  
  6225.  To dump a user database:
  6226.  
  6227.  
  6228.    1.  Make sure the dump device exists, or add it with sp_addumpdevice. (See
  6229.        Chapter 5, "Managing Storage," for details on adding a dump device.)
  6230.  
  6231.    2.  Make sure that the disk or diskette device you dump to or load from is
  6232.        attached to the same computer on which SQL Server is running.
  6233.  
  6234.    3.  For a diskette dump device, make sure that diskettes are formatted and
  6235.        not write-protected.
  6236.  
  6237.    4.  For a diskette dump device, make sure that someone is at the server to
  6238.        insert diskettes.
  6239.  
  6240.    5.  Execute the DUMP DATABASE statement from the SQL Query Window.
  6241.  
  6242.        If you are backing up to diskettes, follow these additional steps
  6243.  
  6244.    6.  Switch to a different screen group from the screen group where SAF is
  6245.        running.
  6246.  
  6247.    7.  Execute the console utility program. Its syntax is as follows:
  6248.  
  6249.        console [/S servername]
  6250.  
  6251.  
  6252.        The /S servername option is required only if you are executing console
  6253.        from a remote computer running MS OS/2.
  6254.  
  6255.  ────────────────────────────────────────────────────────────────────────────
  6256.  NOTE
  6257.  
  6258.  The console utility program is not available under
  6259.  
  6260.  
  6261.    8.  Follow the prompts in the console utility program, which tell you when
  6262.        to insert diskettes.
  6263.  
  6264.  
  6265.  The DUMP DATABASE statement has the following syntax:
  6266.  
  6267.    DUMP DATABASE database_name
  6268.     TO dump_device
  6269.  
  6270.  ────────────────────────────────────────────────────────────────────────────
  6271.  database_name
  6272.    The name of the database from which you are copying data
  6273.  
  6274.  dump_device
  6275.    The logical name of the dump device to which you are dumping the database
  6276.  
  6277.  ────────────────────────────────────────────────────────────────────────────
  6278.  Here's how you'd dump the pubs database to the diskettedumpa diskette:
  6279.  
  6280.    dump database pubs
  6281.     to diskettedumpa
  6282.  
  6283.  Permission to dump databases defaults to the Database Owner and can be
  6284.  transferred to other users.
  6285.  
  6286.  
  6287.  Dumping a Transaction Log
  6288.  
  6289.  The transaction log cannot be backed up separately from the database itself
  6290.  if it is stored in the same database device as the database. This is
  6291.  sometimes the situation with small databases (less than about 4 megabytes).
  6292.  If your database is larger than about 4 megabytes, the transaction log
  6293.  should be stored in a separate database device and backed up separately from
  6294.  the database.
  6295.  
  6296.  ────────────────────────────────────────────────────────────────────────────
  6297.  NOTE
  6298.  
  6299.  You should not dump a transaction log unless at least one previous dump of
  6300.  the database has been made.
  6301.  ────────────────────────────────────────────────────────────────────────────
  6302.  
  6303.  When the log is in a different database device, you can back it up
  6304.  separately from the rest of the database with the DUMP TRANSACTION
  6305.  statement. The backup copy can be read only by the LOAD TRANSACTION
  6306.  statement.
  6307.  
  6308.  Dumping a transaction log takes less time and uses less storage space than
  6309.  dumping a database. Typically, a transaction log dump is made much more
  6310.  frequently (possibly once a day) than a database dump (possibly once a
  6311.  week).
  6312.  
  6313.  A transaction log dump, like a database dump, can take place while the
  6314.  database is active.
  6315.  
  6316.  Two database options, select into/bulkcopy and trunc. log on chkpt., affect
  6317.  transaction log dumps. When either or both of these database options are set
  6318.  to true, you are not allowed to dump the transaction log because changes
  6319.  would not be recoverable. In this situation, executing the DUMP TRANSACTION
  6320.  statement produces an error message instructing you to use DUMP DATABASE
  6321.  instead.
  6322.  
  6323.  By default, these options are set to "false" in newly created databases. See
  6324.  Chapter 9, "Fine-tuning Performance and Operations," for information on
  6325.  database options.
  6326.  
  6327.  
  6328.  Dumping a Transaction Log Using the Admin Menu
  6329.  
  6330.  To dump a transaction log:
  6331.  
  6332.  
  6333.    1.  Select the Admin menu and choose Backup.
  6334.  
  6335.        The "Backup (Dump) Database" dialog box appears.
  6336.  
  6337.    2.  Select the "Transaction log" option button.
  6338.  
  6339.    3.  Select the name of the database whose transaction log will be backed
  6340.        up from the "Database name" list box.
  6341.  
  6342.    4.  Select the name of the dump device to which the transaction log will
  6343.        be backed up from the "Dump device" list box.
  6344.  
  6345.    5.  Choose OK.
  6346.  
  6347.    6.  If you are dumping the database to a diskette, follow the directions
  6348.        on the screen. These directions tell you when to insert diskettes.
  6349.  
  6350.        If you are dumping the database to a hard disk, the dump begins
  6351.        immediately.
  6352.  
  6353.  
  6354.  
  6355.  Dumping a Transaction Log Using System Procedures
  6356.  
  6357.  The DUMP TRANSACTION statement has the following syntax:
  6358.  
  6359.    DUMP TRANSACTION database_name
  6360.     [TO dump_device]
  6361.     [WITH TRUNCATE_ONLY]
  6362.     [WITH NO_LOG]
  6363.  
  6364.  ────────────────────────────────────────────────────────────────────────────
  6365.  TO dump_device
  6366.    The logical name of the dump device to which you are dumping the specified
  6367.    transaction log.
  6368.  
  6369.    The dump device name is optional if you use the WITH TRUNCATE_ONLY or WITH
  6370.    NO_LOG clause.
  6371.  
  6372.  WITH TRUNCATE_ONLY
  6373.    Removes the inactive part of the log without making a backup copy of it.
  6374.    This frees disk space used by the transaction log.
  6375.  
  6376.    WITH TRUNCATE_ONLY is used after you have backed up the entire database
  6377.    with DUMP DATABASE. The DUMP DATABASE statement backs up the log but does
  6378.    not remove the inactive portion of it. If you use WITH TRUNCATE_ONLY and
  6379.    do not have a backup created by DUMP DATABASE, the changes that had been
  6380.    recorded in the log are not recoverable.
  6381.  
  6382.    Since the WITH TRUNCATE_ONLY option does not perform a dump, you can use
  6383.    any dump device name.
  6384.  
  6385.    You cannot use both WITH TRUNCATE_ONLY and WITH NO_LOG in the same
  6386.    statement.
  6387.  
  6388.  WITH NO_LOG
  6389.    Used only when you have run out of space in the database so that you
  6390.    cannot even execute DUMP TRANSACTION WITH TRUNCATE_ONLY to retrieve some
  6391.    space from the log. Like WITH TRUNCATE_ONLY, WITH NO_LOG removes the
  6392.    inactive part of the log without making a backup copy of it. In addition,
  6393.    WITH NO_LOG saves space by not recording this procedure in the transaction
  6394.    log.
  6395.  
  6396.    After the transaction log has been dumped using WITH NO_LOG, the changes
  6397.    that had been recorded in the log are not recoverable. You should
  6398.    immediately execute DUMP DATABASE and then enlarge the database with ALTER
  6399.    DATABASE.
  6400.  
  6401.    You cannot use both WITH TRUNCATE_ONLY and WITH NO_LOG in the same
  6402.    statement.
  6403.  
  6404.  ────────────────────────────────────────────────────────────────────────────
  6405.  DUMP TRANSACTION removes committed transactions from the log after they are
  6406.  written to the dump device. DUMP DATABASE, on the other hand, does not.
  6407.  
  6408.  ────────────────────────────────────────────────────────────────────────────
  6409.  NOTE
  6410.  
  6411.  If you always use DUMP DATABASE (backing up the database and the log) and
  6412.  never use DUMP TRANSACTION, the transaction log will never be cleared out
  6413.  and will become very large. You can avoid this problem by setting the trunc.
  6414.  log on chkpt. option with sp_dboption.
  6415.  ────────────────────────────────────────────────────────────────────────────
  6416.  
  6417.  The DUMP TRANSACTION statement both removes the inactive portion of the log
  6418.  and makes a backup copy. The optional phrase WITH TRUNCATE_ONLY removes the
  6419.  inactive part of the log without making a backup copy of it.
  6420.  
  6421.  ────────────────────────────────────────────────────────────────────────────
  6422.  WARNING
  6423.  
  6424.  If you use WITH TRUNCATE_ONLY and do not have a backup of the transaction
  6425.  log created by DUMP DATABASE, the changes that had been recorded in the log
  6426.  are not recoverable.
  6427.  ────────────────────────────────────────────────────────────────────────────
  6428.  
  6429.  Each time you execute DUMP DATABASE, you should execute DUMP TRANSACTION
  6430.  WITH TRUNCATE_ONLY to clear out the log.
  6431.  
  6432.  The optional WITH NO_LOG clause is used only when you have run out of space
  6433.  in the database and cannot execute DUMP TRANSACTION WITH TRUNCATE_ONLY to
  6434.  retrieve space from the log. Like WITH TRUNCATE_ONLY, WITH NO_LOG removes
  6435.  the inactive part of the log without making a backup copy of it. In
  6436.  addition, WITH NO_LOG saves space by not recording this procedure in the
  6437.  transaction log.
  6438.  
  6439.  ────────────────────────────────────────────────────────────────────────────
  6440.  WARNING
  6441.  
  6442.  After the transaction log has been dumped using WITH NO_LOG, the changes
  6443.  that had been recorded in the log are not recoverable. You should
  6444.  immediately execute DUMP DATABASE and then enlarge the database with ALTER
  6445.  DATABASE.
  6446.  ────────────────────────────────────────────────────────────────────────────
  6447.  
  6448.  
  6449.  Truncating a Transaction Log
  6450.  
  6451.  Truncating a transaction log removes the inactive portion of the log. You
  6452.  usually truncate a transaction log after you have backed up an entire
  6453.  database. Backing up the database also backs up the log but does not remove
  6454.  the inactive portion of it.
  6455.  
  6456.  
  6457.  Truncating a Transaction Log Using the Admin Menu
  6458.  
  6459.  To truncate the transaction log for a specific database:
  6460.  
  6461.  
  6462.    1.  Select the Admin menu and choose Backup.
  6463.  
  6464.        The "Backup (Dump) Database" dialog box appears.
  6465.  
  6466.    2.  Select "Truncate log."
  6467.  
  6468.    3.  Select the name of the database whose transaction log will be
  6469.        truncated from the "Database name" list box.
  6470.  
  6471.    4.  Choose OK.
  6472.  
  6473.        The specified transaction log is truncated.
  6474.  
  6475.  
  6476.  
  6477.  Truncating a Transaction Log Using System Procedures
  6478.  
  6479.  Use the DUMP TRANSACTION statement to truncate a transaction log. See
  6480.  "Dumping a Transaction Log Using System Procedures," earlier in this
  6481.  chapter, for more information.
  6482.  
  6483.  
  6484.  Interactions between Backing Up a Database and Its Log
  6485.  
  6486.  You should not dump a transaction log unless at least one previous dump of
  6487.  the database has been made. Figure 8.1 shows the interaction between dumps
  6488.  of a database and dumps of its transaction log.
  6489.  
  6490.  (This figure may be found in the printed book.)
  6491.  
  6492.  If a media failure were to occur at 5:01 P.M. on Tuesday, all you would need
  6493.  to do (assuming that the media failure was not due to a hardware problem) is
  6494.  load Diskette set 5, which is a database dump that was made at 5:00 P.M. The
  6495.  only work lost would be whatever had been done in the minute between the
  6496.  database dump and the failure.
  6497.  
  6498.  But what if the failure occurred at 4:59 P.M. on Tuesday? In that case,
  6499.  you'd load Diskette set 1, the database dump that was made at 5 P.M. on
  6500.  Friday. Then you'd load Diskette sets 2, 3, and 4, the transaction dumps
  6501.  made since the last complete database dump.
  6502.  
  6503.  After all the transaction diskettes were loaded, the system would be in the
  6504.  exact state it had been in on Tuesday at 10 A.M., resulting in the loss of
  6505.  Tuesday's work. This example illustrates the need for frequent transaction
  6506.  log dumps.
  6507.  
  6508.  
  6509.  Loading a Database
  6510.  
  6511.  The real question is not whether you'll need your backups, but when. After a
  6512.  media crash, you restart SQL Server in the usual way. If SQL Server cannot
  6513.  access (USE) a database, it marks it as suspect, locks it, and displays a
  6514.  warning message. A damaged database must be dropped, either with the DROP
  6515.  DATABASE statement or with DBCC REPAIR DROPDB. At that point, the SA or
  6516.  Database Owner can load the most recent database dump (and any transaction
  6517.  logs).
  6518.  
  6519.  
  6520.  Loading a Database Using the Admin Menu
  6521.  
  6522.  To load a database:
  6523.  
  6524.  
  6525.    1.  Select the Admin menu and choose Restore.
  6526.  
  6527.        The "Restore (Load) Database" dialog box appears.
  6528.  
  6529.    2.  Select "Database."
  6530.  
  6531.    3.  Select the name of the database to be loaded from the "Database name"
  6532.        list box.
  6533.  
  6534.    4.  Select the name of the dump device from which the database will be
  6535.        loaded from the "Load device" list box.
  6536.  
  6537.    5.  Choose OK.
  6538.  
  6539.    6.  If you are loading the database from a diskette, follow the directions
  6540.        on the screen. These directions tell you when to insert diskettes.
  6541.  
  6542.        If you are loading the database to a hard disk, the load begins
  6543.        immediately.
  6544.  
  6545.  
  6546.  
  6547.  Loading a Database Using System Procedures
  6548.  
  6549.  The LOAD DATABASE statement is designed for user databases only. The master
  6550.  database is restored differently, as described later in this chapter.
  6551.  
  6552.  Loading a database locks it so that no one can modify it while recovery is
  6553.  in process. Users are free to access and modify other databases on SQL
  6554.  Server during this time.
  6555.  
  6556.  When SQL Server loads a database, it rolls back any uncommitted transactions
  6557.  that were active at the moment the dump began. When the load is complete,
  6558.  the database is in the same state it was in at the moment the DUMP statement
  6559.  was executed, minus any transactions that were active at that point.
  6560.  
  6561.  If a failure occurs while a database is being loaded, SQL Server does not
  6562.  recover the partially loaded database and notifies the SA. The database load
  6563.  must be restarted by reexecuting the LOAD statement.
  6564.  
  6565.  The LOAD DATABASE statement has the following syntax:
  6566.  
  6567.    LOAD DATABASE database_name
  6568.      FROM dump_device
  6569.  
  6570.  ────────────────────────────────────────────────────────────────────────────
  6571.  database_name
  6572.    The destination database. It can be either a newly created database with
  6573.    no data or an existing database. Loading dumped data to an existing
  6574.    database replaces existing data with the loaded data. The database into
  6575.    which you load a dumped database must be large enough to hold the dumped
  6576.    data.
  6577.  
  6578.  FROM dump_device
  6579.    The logical name of the dump device from which you are loading the
  6580.    database.
  6581.  
  6582.  ────────────────────────────────────────────────────────────────────────────
  6583.  The destination database must be large enough to hold the amount of storage
  6584.  space that was actually allocated to the dumped database. The actual amount
  6585.  of data the dumped database contains is irrelevant.
  6586.  
  6587.  Information on storage space allocated can be obtained with the DBCC
  6588.  CHECKALLOC statement.
  6589.  
  6590.  
  6591.  Loading a Transaction Log
  6592.  
  6593.  Loading a transaction log recovers as much of a database as possible in case
  6594.  of system failure.
  6595.  
  6596.  The backups of the transaction log must be loaded in the same sequence in
  6597.  which they were made. SQL Server checks the timestamps on each dumped
  6598.  database and each dumped transaction log to see that the sequence is
  6599.  correct.
  6600.  
  6601.  Loading a transaction log dump results in reexecution of the changes it
  6602.  contains and rolling back any transactions that were uncommitted when the
  6603.  transaction log was dumped. After the transaction log is loaded, the
  6604.  database is in the state it was in at the moment the log was dumped, minus
  6605.  any transactions that were active at that point. (The exception to this is
  6606.  the DUMP TRANSACTION statement itself, which by definition was active at
  6607.  that point. It is not rolled back. Rather, it is completed by the next LOAD
  6608.  TRANSACTION statement.)
  6609.  
  6610.  Thus, when the entire sequence of transaction log dumps has been loaded, the
  6611.  database is restored to its state at the time of the last transaction log
  6612.  dump (minus active transactions).
  6613.  
  6614.  
  6615.  Loading a Transaction Log Using the Admin Menu
  6616.  
  6617.  To load a transaction log:
  6618.  
  6619.  
  6620.    1.  Select the Admin menu and choose Restore.
  6621.  
  6622.        The "Restore (Load) Database" dialog box appears.
  6623.  
  6624.    2.  Select the "Transaction log" option button.
  6625.  
  6626.    3.  Select the name of the database whose transaction log will be loaded
  6627.        from the "Database name" list box.
  6628.  
  6629.    4.  Select the name of the dump device from which the transaction log will
  6630.        be loaded from the "Load device" list box.
  6631.  
  6632.    5.  Choose OK.
  6633.  
  6634.    6.  If you are loading the transaction log to a diskette, follow the
  6635.        directions on the screen. These directions tell you when to insert
  6636.        diskettes.
  6637.  
  6638.        If you are loading the transaction log to a hard disk, the load begins
  6639.        immediately.
  6640.  
  6641.  
  6642.  
  6643.  Loading a Transaction Log Using System Procedures
  6644.  
  6645.  The LOAD TRANSACTION statement has the following syntax:
  6646.  
  6647.    LOAD TRANSACTION database_name
  6648.     FROM dump_device
  6649.  
  6650.  ────────────────────────────────────────────────────────────────────────────
  6651.  database_name
  6652.    The name of the destination database.
  6653.  
  6654.  FROM dump_device
  6655.    The logical name of the dump device from which the transaction log is
  6656.    being loaded. LOAD TRANSACTION can be used only after the database has
  6657.    been restored from a backup made with the DUMP DATABASE statement. Once
  6658.    you've reloaded a database, you can load one or more transaction logs.
  6659.  
  6660.  ────────────────────────────────────────────────────────────────────────────
  6661.  Keeping Transaction Logs Small
  6662.  
  6663.  In a development environment, the most important system administration
  6664.  requirement may be to maximize the amount of space available in database
  6665.  devices at all times. In this situation, the ability to recover databases
  6666.  may not be as stringent a requirement as in a production environment.
  6667.  
  6668.  An SA can exercise various options for truncating the transaction logs of
  6669.  databases to keep them as small as possible. These options are as follows:
  6670.  
  6671.  
  6672.    ■   The DUMP TRANSACTION statement with the WITH TRUNCATE_ONLY option
  6673.  
  6674.    ■   The DUMP TRANSACTION statement with the WITH NO_LOG option
  6675.  
  6676.    ■   sp_dboption with the trunc. log on checkpoint option
  6677.  
  6678.  
  6679.  All three of these options truncate the log of a specified database without
  6680.  making a backup copy of the log.
  6681.  
  6682.  The trunc. log on chkpt. option of sp_dboption clears out the transaction
  6683.  log every time SQL Server initiates the checkpoint checking process (about
  6684.  once a minute). Set this option only if the log is in the same file as the
  6685.  database so that you are always dumping entire databases or if you don't
  6686.  care about recovering from a media crash. If you plan to dump the complete
  6687.  database and never to dump the transaction log alone, you should also
  6688.  consider setting this option.
  6689.  
  6690.  If you leave the trunc. log on chkpt. option off (the default condition) and
  6691.  never dump the transaction log, it will continue to grow and you may run out
  6692.  of space in your database.
  6693.  
  6694.  
  6695.  If You Run Out of Space in a Database
  6696.  
  6697.  If you run out of space in a database, execute the DUMP TRANSACTION
  6698.  statement with the WITH TRUNCATE_ONLY option or (if you've also run out of
  6699.  space in the log) with the WITH NO_LOG option to recover space occupied by
  6700.  the log. Then immediately dump the database. You can subsequently use ALTER
  6701.  DATABASE to extend your database onto another database device.
  6702.  
  6703.  The null device name diskdump can be used with either of the DUMP
  6704.  TRANSACTION statements.
  6705.  
  6706.  Setting the trunc. log on chkpt. option is a sure way to save space, but it
  6707.  means that you can only recover the state of the database as it was at the
  6708.  last database dump.
  6709.  
  6710.  
  6711.  Moving a Database
  6712.  
  6713.  You can use the DUMP and LOAD statements to move a database to another
  6714.  database device. The procedure follows:
  6715.  
  6716.  
  6717.    1.  Make sure the new database device is listed in sysdevices.
  6718.  
  6719.    2.  Dump the database.
  6720.  
  6721.    3.  Use the DROP DATABASE statement to remove the old database.
  6722.  
  6723.    4.  Use the CREATE DATABASE statement to create the new database, and
  6724.        specify the new database device.
  6725.  
  6726.    5.  Use the LOAD DATABASE statement to load the database from the backup.
  6727.  
  6728.  
  6729.  To move a database to another server, follow the same procedure. However, if
  6730.  the syslogins table on the new server is different than the old one, the
  6731.  ownership of databases and database objects will be incorrect. Use aliases
  6732.  to map owners to their objects on the new SQL Server.
  6733.  
  6734.  
  6735.  Restoring the master Database
  6736.  
  6737.  The procedure to recover a damaged master database is different than for
  6738.  recovery of user databases. A damaged master database makes itself known
  6739.  either with an inability to start SQL Server, by segmentation faults or
  6740.  input/output errors, and/or in a report from DBCC. It can be caused by a
  6741.  media failure in the area in which master is stored.
  6742.  
  6743.  If the master database becomes unusable, it must be restored from a previous
  6744.  dump. All changes made to the master database after the last dump will be
  6745.  lost when the dump is reloaded. They must be reapplied.
  6746.  
  6747.  Therefore, it is strongly recommended that the master database be backed up
  6748.  each time it is changed. This is best accomplished by prohibiting the
  6749.  creation of user-defined objects in master and by being aware of the
  6750.  statements and system procedures that modify it. The most common are as
  6751.  follows:
  6752.  
  6753.  
  6754.    ■   DISK INIT, sp_addumpdevice, and sp_dropdevice
  6755.  
  6756.    ■   CREATE DATABASE and ALTER DATABASE
  6757.  
  6758.    ■   sp_addlogin and sp_droplogin
  6759.  
  6760.  
  6761.  Changes such as adding or dropping a dump device, or adding or deleting a
  6762.  login ID can be reapplied manually or with batch files.
  6763.  
  6764.  Changes using DISK INIT, CREATE DATABASE, and ALTER DATABASE are far more
  6765.  serious. If a user database is created or expanded after the most recent
  6766.  dump of the master database and if it becomes necessary to reload the master
  6767.  database, then the user database and all of the data in it will be lost.
  6768.  This is why the master database should be dumped after the creation or
  6769.  expansion of user databases.
  6770.  
  6771.  To restore a damaged master database, the SA must follow these steps:
  6772.  
  6773.  
  6774.    1.  Rebuild the master database with the bldmastr program. (See the next
  6775.        section, "Building the master Database.")
  6776.  
  6777.    2.  Start SQL Server in single-user mode. (See "Starting SQL Server in
  6778.        Single-User Mode," later in this chapter.)
  6779.  
  6780.    3.  Add a dump device if the dump was not made to diskettes. (See "Adding
  6781.        a Dump Device," later in this chapter.)
  6782.  
  6783.    4.  Reload the master database from the most recent dump. (See "Reloading
  6784.        the master Database," later in this chapter.)
  6785.  
  6786.    5.  Apply changes (if any) not included in the most recent dump. (See
  6787.        "Applying Changes," later in this chapter)
  6788.  
  6789.  
  6790.  
  6791.  Building the master Database
  6792.  
  6793.  If the MS OS/2 file containing master is physically intact, you can rebuild
  6794.  the master database without altering configuration (or other) data. Execute
  6795.  bldmastr with the /d and /m options, as follows:
  6796.  
  6797.    bldmastr /d c:\sql\data\master.dat /m
  6798.  
  6799.  "c:\sql\data\master.dat" is the physical filename of the master database
  6800.  device.
  6801.  
  6802.  If the MS OS/2 file containing master is unusable due to media failure, you
  6803.  must create a completely new master.dat file and execute bldmastr. For
  6804.  example, to rebuild a new non-case-sensitive master database with a size of
  6805.  15 megabytes, execute bldmastr as follows:
  6806.  
  6807.    bldmastr /d c:\sql\data\master.dat /s 7680 /C
  6808.  
  6809.  ────────────────────────────────────────────────────────────────────────────
  6810.  /d
  6811.    Specifies the physical filename of the master database device
  6812.  
  6813.  /s
  6814.    Specifies the size in 2K blocks (10 megabytes = 5120 2K blocks)
  6815.  
  6816.  /C
  6817.    Specifies non-case-sensitive (optional)
  6818.  
  6819.  ────────────────────────────────────────────────────────────────────────────
  6820.  See the SQL Server Language Reference for complete information on the
  6821.  bldmastr utility program.
  6822.  
  6823.  
  6824.  Starting SQL Server in Single-User Mode
  6825.  
  6826.  Start SQL Server in single-user mode by executing sqlservr as follows:
  6827.  
  6828.    sqlservr /d c:\sql\data\master.dat /m
  6829.  
  6830.  ────────────────────────────────────────────────────────────────────────────
  6831.  /d
  6832.    Specifies the physical filename of the master database device
  6833.  
  6834.  /m
  6835.    Specifies single-user mode
  6836.  
  6837.  ────────────────────────────────────────────────────────────────────────────
  6838.  You can execute sqlservr from the server or from a workstation.
  6839.  
  6840.  
  6841.  Adding a Dump Device
  6842.  
  6843.  If the dump of master was made to a hard disk rather than to a diskette, you
  6844.  must add a dump device with sp_addumpdevice before performing the load. To
  6845.  do this, you must first load the stored procedures.
  6846.  
  6847.  Load the stored procedures from the instmstr.sql batch file using isql.
  6848.  
  6849.    isql /U sa /P /i c:\sql\install\instmstr.sql
  6850.  
  6851.  When this is done, use isql to add the dump device as follows:
  6852.  
  6853.    isql /U sa /P
  6854.     sp_addumpdevice 'disk', 'logical_name', 'physical_name', 2
  6855.  
  6856.  ────────────────────────────────────────────────────────────────────────────
  6857.  logical_name
  6858.    The logical name of the disk dump device
  6859.  
  6860.  physical_name
  6861.    The physical name of the MS OS/2 file that contains the dump of master
  6862.  
  6863.  2
  6864.    The controller type (2 = hard disk)
  6865.  
  6866.  ────────────────────────────────────────────────────────────────────────────
  6867.  Reloading the master Database
  6868.  
  6869.  Reload the most recent dump of the master database using the LOAD DATABASE
  6870.  statement. The server must be in single-user mode for this statement to
  6871.  operate on master. When the load of master is complete, the server
  6872.  automatically shuts itself down.
  6873.  
  6874.  Unless it has been changed by the SA, the master database does not have a
  6875.  separate transaction log device, and no special action is required to load
  6876.  it.
  6877.  
  6878.  If the master database has been changed to use a separate log device and if
  6879.  that transaction log has been dumped after the most recent dump of the
  6880.  master database, then you must reload the transaction log for the master
  6881.  database. The server must be shut down to do this. Use the LOAD TRANSACTION
  6882.  statement to load the transaction log.
  6883.  
  6884.  
  6885.  Applying Changes
  6886.  
  6887.  If there have been no changes to the master database since the last dump,
  6888.  then you are done. Restart the server in multiuser mode.
  6889.  
  6890.  If login IDs or devices have been added to or dropped from the master
  6891.  database since the last dump, those changes must be reapplied. Restart the
  6892.  server and reapply the changes manually or from saved batch files.
  6893.  
  6894.  If databases have been created or expanded since the last dump of master,
  6895.  those databases must be re-created and all of data contained in them must be
  6896.  reentered. This can be done manually, from saved batch files, or by
  6897.  reloading dumps of those databases after they have been re-created.
  6898.  
  6899.  If you have made many changes and have no recent dump, it is possible in
  6900.  some cases to regain data in user databases that has been lost by reloading
  6901.  master. The technique requires the use of DISK REINIT and DISK REFIT and may
  6902.  involve manual modifications to master database tables. If you feel this
  6903.  technique is necessary, contact your vendor's technical support before
  6904.  beginning the recovery process.
  6905.  
  6906.  The safest approach is to always dump the master database after creating or
  6907.  altering databases.
  6908.  
  6909.  After all the changes since the last dump of master have been applied,
  6910.  restart the server in multiuser mode.
  6911.  
  6912.  
  6913.  Recovering from Media Failure
  6914.  
  6915.  To recover user databases from media failure, re-create the lost devices and
  6916.  then load the affected databases from backups. Anything done after the
  6917.  backups were created must be reapplied.
  6918.  
  6919.  
  6920.  Re-creating Lost Devices and Reloading Lost Databases
  6921.  
  6922.  To restore a backup, the target database must already exist. It doesn't have
  6923.  to occupy the same devices, but it must have enough space allocated to hold
  6924.  the information in that database at the time it was dumped.
  6925.  
  6926.  To re-create the lost devices:
  6927.  
  6928.  
  6929.    1.  Start SQL Server in single-user mode.
  6930.  
  6931.    2.  Execute the DISK REFIT statement.
  6932.  
  6933.        DISK REFIT drops entries in the sysusages table that can no longer be
  6934.        physically accessed and drops the related sysdatabases entries.
  6935.  
  6936.    3.  Drop sysusages entries related to databases that have been dropped:
  6937.  
  6938.        DELETE FROM SYSUSAGES WHERE DBID NOT IN
  6939.                 (SELECT DBID FROM SYSDATABASES)
  6940.  
  6941.  
  6942.    4.  Drop lost devices using the sp_dropdevice system procedure.
  6943.  
  6944.    5.  Execute CHECKPOINT, shut down SQL server, and then start in normal
  6945.        mode.
  6946.  
  6947.    6.  Re-create lost devices by executing the DISK INIT statement using the
  6948.        virtual device number (VDEVNO) and size of the original devices. (If
  6949.        you do not know the virtual device number and size of the original
  6950.        devices, see the next section, "Finding Information on Lost Devices
  6951.        and Databases.")
  6952.  
  6953.  
  6954.  To re-create and reload the affected databases:
  6955.  
  6956.  
  6957.    1.  Re-create affected databases using the same size and device assignment
  6958.        as the original databases. (If you do not know the size and device
  6959.        assignment, see the next section, "Finding Information on Lost Devices
  6960.        and Databases.")
  6961.  
  6962.    2.  Assign log devices, if necessary, with the sp_logdevice system
  6963.        procedure.
  6964.  
  6965.    3.  Load the affected databases and transaction logs from the latest
  6966.        backups.
  6967.  
  6968.  
  6969.  
  6970.  Finding Information on Lost Devices and Databases
  6971.  
  6972.  If the virtual device number and size of the original devices are not known,
  6973.  they can be derived from the sysdevices, sysdatabases, and sysusages tables
  6974.  in the master database.
  6975.  
  6976.  The virtual device number (VDEVNO) and device size can be derived from the
  6977.  low and high columns in sysdevices. VDEVNO is low divided by 16777216.
  6978.  Device size ishigh - low (2K blocks).
  6979.  
  6980.  The size and device assignment of databases can be derived from the
  6981.  sysdevices, sysusages, and sysdatabases tables. Each chunk of disk space
  6982.  assigned to a database is represented by a row in the sysusages table. The
  6983.  size of each chunk is in the row. The dbid of the database to which the
  6984.  chunk is assigned is also in the row, and the corresponding database name
  6985.  can be obtained from sysdatabases. The device containing the chunk of disk
  6986.  space can be deduced by noticing which low/high range in sysdevices contains
  6987.  the starting virtual address (VSTART) specified in the sysusages table.
  6988.  
  6989.  To determine whether a device is a log device, look at the value of segmap
  6990.  in sysusages. The value "7" indicates log and data, "4" indicates log only,
  6991.  and "3" indicates data only.
  6992.  
  6993.  
  6994.  Examples of Recovery from Media Failure
  6995.  
  6996.  The following examples assume two user databases in addition to the master
  6997.  database and two database devices in addition to the master database device.
  6998.  Device 1 is 4 megabytes and was created first (VDEVNO = 1), while device 2
  6999.  is 6 megabytes and was created after device 1 (VDEVNO = 2). User database 1
  7000.  was allocated 2 megabytes on device 1, 2 megabytes on master.dat, and a
  7001.  1-megabyte log on device 2. User database 2 was allocated 2 megabytes on
  7002.  device 2 and 2 megabytes on device 1.
  7003.  
  7004.  
  7005.  Example 1: One Device Lost; Other Devices Intact
  7006.  
  7007.  For this example, assume that user database device 1 has been lost and the
  7008.  other devices are intact.
  7009.  
  7010.  Follow these steps:
  7011.  
  7012.  
  7013.    1.  Start SQL Server in single-user mode (use the -m option).
  7014.  
  7015.    2.  Execute the DISK REFIT statement. All entries in the sysusages table
  7016.        that were allocated on device 1 are dropped. User database 1 is also
  7017.        dropped because its first entry in the sysusages table was dropped.
  7018.        The other entries in the sysusages table for databases 1 and 2 that
  7019.        were allocated on device 2 and master.dat are not dropped, even though
  7020.        they relate to the dropped database.
  7021.  
  7022.    3.  Drop the remaining sysusages entries that relate to the dropped
  7023.        database.
  7024.  
  7025.    4.  Drop device 1 using the sp_dropdevice system procedure.
  7026.  
  7027.    5.  Execute CHECKPOINT, shut down SQL Server, and then start SQL Server in
  7028.        normal mode.
  7029.  
  7030.    6.  Re-create device 1 by executing the DISK INIT statement with a size of
  7031.        4 megabytes and a virtual device number (VDEVNO) of 1.
  7032.  
  7033.    7.  Re-create user database 1 with 2 megabytes on device 1, 2 megabytes on
  7034.        master.dat, and 1 megabyte on device 2. Re-create user database 2 with
  7035.        2 megabytes on device 2 and 2 megabytes on device 1.
  7036.  
  7037.    8.  Designate the log for database 1 using the sp_logdevice system
  7038.        procedure.
  7039.  
  7040.    9.  Load database 1 and its transaction log from backup. Load database 2
  7041.        from backup.
  7042.  
  7043.  
  7044.  
  7045.  Example 2: User Devices Lost; master.dat Intact
  7046.  
  7047.  For this example, assume that both user database devices have been lost and
  7048.  master.dat is intact.
  7049.  
  7050.  Follow these steps:
  7051.  
  7052.  
  7053.    1.  Start SQL Server in single-user mode (using the -m option).
  7054.  
  7055.    2.  Execute the DISK REFIT statement. All entries in the sysusages table
  7056.        that were allocated on devices 1 and 2 are dropped. User databases 1
  7057.        and 2 are also dropped because their first entries in the sysusages
  7058.        table were dropped. The single sysusages entry for database 1 that was
  7059.        allocated on master.dat is not dropped, even though it relates to a
  7060.        dropped database.
  7061.  
  7062.    3.  Drop the remaining sysusages entry that relates to database 1.
  7063.  
  7064.    4.  Drop devices 1 and 2 using the sp_dropdevice system procedure.
  7065.  
  7066.    5.  Execute CHECKPOINT, shut down SQL Server, and then start in normal
  7067.        mode.
  7068.  
  7069.    6.  Re-create device 1 by executing the DISK INIT statement with a size of
  7070.        4 megabytes and a virtual device number (VDEVNO) of 1. Re-create
  7071.        device 2 by executing the DISK INIT statement with a size of 6
  7072.        megabytes and a virtual device number (VDEVNO) of 2.
  7073.  
  7074.    7.  Re-create user database 1 with 2 megabytes on device 1, 2 megabytes on
  7075.        master.dat, and 1 megabyte on device 2. Re-create user database 2 with
  7076.        2 megabytes on device 2 and 2 megabytes on device 1.
  7077.  
  7078.    8.  Designate the log for database 1 using the sp_logdevice system
  7079.        procedure.
  7080.  
  7081.    9.  Load database 1 and its transaction log from backup. Load database 2
  7082.        from backup.
  7083.  
  7084.  
  7085.  
  7086.  Example 3: All Devices Lost
  7087.  
  7088.  For this example, assume that all three database devices have been lost. In
  7089.  this case, master.dat must be restored first.
  7090.  
  7091.  Follow these steps:
  7092.  
  7093.  
  7094.    1.  Run bldmastr to re-create master.dat using the original size and
  7095.        case-sensitivity option.
  7096.  
  7097.    2.  Start SQL Server in single-user mode and restore the latest backup of
  7098.        the master database. If your dump of master was made with a
  7099.        user-supplied dump device, that dump device must be re-added to the
  7100.        sysdevices table before the restore can take place.
  7101.  
  7102.        The quickest way to do this is to insert a row into sysdevices. It can
  7103.        also be done with the sp_addumpdevice system procedure, but that
  7104.        method requires the instmstr.sql script to be run first to re-add the
  7105.        stored procedures.
  7106.  
  7107.        The server shuts itself down when the restore is complete.
  7108.  
  7109.    3.  Re-create device 1 by executing the DISK INIT statement with a size of
  7110.        4 megabytes and a virtual device number (VDEVNO) of 1. Re-create
  7111.        device 2 by executing the DISK INIT statement with a size of 6
  7112.        megabytes and a virtual device number (VDEVNO) of 2.
  7113.  
  7114.    4.  Re-create user database 1 with 2 megabytes on device 1, 2 megabytes on
  7115.        master.dat, and 1 megabyte on device 2. Re-create user database 2 with
  7116.        2 megabytes on device 2 and 2 megabytes on device 1.
  7117.  
  7118.    5.  Designate the log for database 1 using the sp_logdevice system
  7119.        procedure.
  7120.  
  7121.    6.  Load database 1 and its transaction log from backup. Load database 2
  7122.        from backup.
  7123.  
  7124.  
  7125.  
  7126.  
  7127.  
  7128.  
  7129.  
  7130.  Chapter 9  Fine-tuning Performance and Operations
  7131.  ────────────────────────────────────────────────────────────────────────────
  7132.  
  7133.  
  7134.  Introduction
  7135.  
  7136.  Once an application is up and running, the SA will want to monitor its
  7137.  performance, and may want to customize and fine-tune it. SQL Server provides
  7138.  software tools for these purposes.
  7139.  
  7140.  This chapter explains how to
  7141.  
  7142.  
  7143.    ■   Tune queries and stored procedures
  7144.  
  7145.    ■   Set a variety of database options
  7146.  
  7147.    ■   Monitor SQL Server activity
  7148.  
  7149.    ■   Ensure that SQL Server makes the best use of existing indexes with the
  7150.        UPDATE STATISTICS statement.
  7151.  
  7152.    ■   Set configuration options
  7153.  
  7154.  
  7155.  
  7156.  Setting Query Options
  7157.  
  7158.  The query options allow you to instruct SQL Server to handle queries and
  7159.  stored procedures in a variety of ways. These options are turned on or off
  7160.  for the duration of the user's work session with the SET statement. No
  7161.  permissions are required for using the SET statement.
  7162.  
  7163.  The SET statement has the following syntax:
  7164.  
  7165.    SET
  7166.     {{ ARITHABORT | ARITHIGNORE |
  7167.     NOCOUNT | NOEXEC |
  7168.     OFFSETS {keyword_list} | PARSEONLY | PROCID |
  7169.     SHOWPLAN | STATISTICS IO | STATISTICS TIME }
  7170.     {ON | OFF} |
  7171.     ROWCOUNT number | TEXTSIZE n}
  7172.  
  7173.  ────────────────────────────────────────────────────────────────────────────
  7174.  ARITHABORT
  7175.    Aborts a query when an overflow or divide-by-zero error occurs during
  7176.    query execution.
  7177.  
  7178.  ARITHIGNORE
  7179.    Returns NULL when an overflow or divide-by-zero error occurs during a
  7180.    query. No warning message is displayed. If neither ARITHABORT nor
  7181.    ARITHIGNORE is set, SQL Server returns NULL and prints a warning message
  7182.    after the query is executed.
  7183.  
  7184.  NOCOUNT
  7185.    Turns off the message returned at the end of each statement that tells you
  7186.    how many rows were affected by the statement. The global variable
  7187.    @ROWCOUNT is updated even when NOCOUNT is set.
  7188.  
  7189.  NOEXEC
  7190.    Compiles each query but does not execute it. NOEXEC is often used with
  7191.    SHOWPLAN. Once NOEXEC is set, no subsequent statements are executed
  7192.    (including other SET statements) until NOEXEC is turned off.
  7193.  
  7194.  OFFSETS keyword_list
  7195.    Returns the offset (position in relation to the beginning of the query) of
  7196.    specified keywords in SQL statements. The keyword list is a list,
  7197.    separated with commas, that can include any of the following SQL
  7198.    statements: SELECT, FROM, ORDER, COMPUTE, TABLE, PROCEDURE, STATEMENT,
  7199.    PARAM, and EXECUTE.
  7200.  
  7201.  PARSEONLY
  7202.    Checks the syntax of each query and returns any error messages without
  7203.    generating a sequence tree, compiling, or executing the query. PARSEONLY
  7204.    returns offsets if the OFFSETS option is set and there are no errors.
  7205.  
  7206.  PROCID
  7207.    Returns the ID number of the stored procedure to DB-LIBRARY (not to the
  7208.    user) before sending rows generated by that stored procedure.
  7209.  
  7210.  SHOWPLAN
  7211.    Generates a description of the processing plan for the query and
  7212.    immediately processes it unless NOEXEC is set.
  7213.  
  7214.  STATISTICS IO
  7215.    Displays the number of scans, the number of logical reads (pages
  7216.    accessed), and the number of physical reads (disk accesses) for each table
  7217.    referenced in the statement; STATISTICS IO displays the number of pages
  7218.    written for each statement.
  7219.  
  7220.  STATISTICS TIME
  7221.    Displays the time it took to parse and compile each statement and the time
  7222.    it took to execute each step of the statement. Times are given in
  7223.    timeticks. Each timetick in MS OS/2 is 31.25 milliseconds (1/32 second).
  7224.  
  7225.  ROWCOUNT number
  7226.    Causes SQL Server to stop processing the query after the specified number
  7227.    of rows are returned. To turn this option off so that all rows are
  7228.    returned, use "SET ROWCOUNT 0".
  7229.  
  7230.  TEXTSIZE n
  7231.    Specifies the size (in bytes) of text type data to be returned with a
  7232.    SELECT statement. The @TEXTSIZE global variable stores the current
  7233.    setting.
  7234.  
  7235.  ────────────────────────────────────────────────────────────────────────────
  7236.  The SET options are divided into four categories:
  7237.  
  7238.  
  7239.    ■   PARSEONLY, NOEXEC, SHOWPLAN, BACKGROUND, ROWCOUNT, and NOCOUNT control
  7240.        the way a query is executed. It doesn't make sense to set both
  7241.        PARSEONLY and NOEXEC.
  7242.  
  7243.        The default setting for ROWCOUNT and TEXTSIZE is 0 (return
  7244.        everything); the default for the others is OFF.
  7245.  
  7246.    ■   The STATISTICS IO and STATISTICS TIME options display performance
  7247.        statistics after each query. The default setting for these options is
  7248.        OFF.
  7249.  
  7250.    ■   ARITHABORT and ARITHIGNORE handle exceptional cases during query
  7251.        execution. You cannot set both ARITHABORT and ARITHIGNORE. The default
  7252.        setting for these options is OFF.
  7253.  
  7254.    ■   OFFSETS and PROCID are used by application programs to interpret
  7255.        results from SQL Server. The default setting for these options is ON.
  7256.  
  7257.  
  7258.  If you use the SET statement inside a trigger or stored procedure, the
  7259.  option reverts to its former setting after the trigger or procedure
  7260.  executes.
  7261.  
  7262.  The following statement causes SQL Server to return a description of the
  7263.  processing plan for each query but not execute it:
  7264.  
  7265.    set showplan on
  7266.     <execute>
  7267.     set noexec on
  7268.     <execute>
  7269.  
  7270.  This statement causes SQL Server to stop processing each query after it
  7271.  returns the first ten rows:
  7272.  
  7273.    set rowcount 10
  7274.  
  7275.  Any options set with a SET statement take effect at the end of the batch.
  7276.  You can combine SET statements and queries in the same batch, but the SET
  7277.  options won't apply to the queries in that batch. Since this batch contains
  7278.  a SET statement and a query, the SET option doesn't take effect:
  7279.  
  7280.    set showplan on
  7281.     select * from publishers
  7282.     <execute>
  7283.  
  7284.     pub_id   pub_name     city   state
  7285.     -----  --------------------  --------  -----
  7286.     0736  New Age Books    Boston   MA
  7287.     0877  Binnet & Hardley   Washington   DC
  7288.     1389  Algodata Infosystems  Berkeley  CA
  7289.  
  7290.     (3 rows affected)
  7291.  
  7292.  If the two statements are put into separate batches, here's what happens:
  7293.  
  7294.    set showplan on
  7295.     <execute>
  7296.     select * from publishers
  7297.     <execute>
  7298.  
  7299.     STEP 1
  7300.     The type of query is SELECT
  7301.     FROM TABLE
  7302.     publishers
  7303.     Nested iteration
  7304.     Table Scan
  7305.  
  7306.     pub_id  pub_name     city   state
  7307.     ------  ---------------------  ----------  ------
  7308.     0736  New Age Books    Boston   MA
  7309.     0877  Binnet & Hardley   Washington   DC
  7310.     1389  Algodata Infosystems  Berkeley  CA
  7311.  
  7312.     (3 rows affected)
  7313.  
  7314.  
  7315.  Setting and Changing Database Options
  7316.  
  7317.  You can set a number of database options for each database and change them
  7318.  as necessary.
  7319.  
  7320.  The sp_dboption system procedure is used both to display and to change a
  7321.  series of database options. None of the master database's option settings
  7322.  can be changed: only user database's options can be changed. However, to
  7323.  change a database option in a user database (or to display a list of the
  7324.  database options), sp_dboption must be executed while using the master
  7325.  database.
  7326.  
  7327.  The sp_dboption system procedure has the following syntax:
  7328.  
  7329.    sp_dboption [dbname, optname, {true | false}]
  7330.  
  7331.  ────────────────────────────────────────────────────────────────────────────
  7332.  dbname
  7333.    The name of the database in which you want to set the option. You must be
  7334.    using master to execute sp_dboption with parameters (that is, to change a
  7335.    database option). However, the database name cannot be master; you cannot
  7336.    change master's database options.
  7337.  
  7338.  optname
  7339.    The name of the option you want to set or turn off. SQL Server understands
  7340.    any unique string that is part of the option name. Use quotation marks
  7341.    around the option name if it includes embedded blanks.
  7342.  
  7343.  true, false
  7344.    Use true if you want to set the option and false if you want to turn off
  7345.    the option.
  7346.  
  7347.  ────────────────────────────────────────────────────────────────────────────
  7348.  To make an option or options take effect for every new database, change the
  7349.  option in the model database.
  7350.  
  7351.  The following database options are available:
  7352.  
  7353.  ────────────────────────────────────────────────────────────────────────────
  7354.  dbo use only
  7355.    When this option is set, only the Database Owner can use the database.
  7356.  
  7357.  no chkpt on recovery
  7358.    When this option is set, an up-to-date copy of a database is kept. In
  7359.    these situations, there is a "primary" and a "secondary" database.
  7360.    Initially, the primary database is dumped and loaded into the secondary
  7361.    database. Then, at intervals, the transaction log of the primary database
  7362.    is automatically dumped and loaded into the secondary database.
  7363.  
  7364.    If this option is turned off─the default condition─a checkpoint record is
  7365.    added to the database after it is recovered due to restarting SQL Server.
  7366.    This checkpoint, which ensures that the recovery mechanism won't
  7367.    unnecessarily be rerun, changes the sequence number on the database. If
  7368.    the sequence number on the secondary database has changed, a subsequent
  7369.    dump of the transaction log from the primary database could not be loaded
  7370.    into it.
  7371.  
  7372.    Setting this option for the secondary database causes it not to get a
  7373.    checkpoint from the recovery process so that subsequent transaction log
  7374.    dumps from the primary database can be loaded into it.
  7375.  
  7376.  read only
  7377.    When this option is set, you can retrieve data from the database but can't
  7378.    modify anything.
  7379.  
  7380.  select into/bulkcopy
  7381.    When this option is set, you can perform nonlogged operations: the
  7382.    WRITETEXT statement, the SELECT INTO statement, or the bcp utility
  7383.    program. By default, tables with no indexes are copied with the fast
  7384.    version of bcp, which means that these operations are not logged to save
  7385.    time. You do not have to set the select into/bulkcopy option to select
  7386.    into a temporary table since the tempdb temporary database is never
  7387.    recovered anyway. The option need not be set to run bcp on a table that
  7388.    has indexes because inserts are logged.
  7389.  
  7390.    When the select into/bulkcopy option is set, you are not allowed to dump
  7391.    the transaction log. In this situation, executing the DUMP TRANSACTION
  7392.    statement produces an error message instructing you to use DUMP DATABASE
  7393.    instead.
  7394.  
  7395.    By default, the select into/bulkcopy option is off in newly created
  7396.    databases. To change the default, set this option in the model database.
  7397.  
  7398.  single user
  7399.    When this option is set, only one user at a time can access the database.
  7400.  
  7401.  trunc. log on chkpt.
  7402.    When this option is set, the transaction log is truncated (committed
  7403.    transactions are removed) every time the CHECKPOINT checking process
  7404.    occurs (usually more than once per minute).
  7405.  
  7406.    It may be useful to set this option while doing development work during
  7407.    which backups of the transaction log are not needed. If this option is off
  7408.    (the original default condition) and the transaction log is never dumped,
  7409.    the transaction log will continue to grow, and you may run out of space in
  7410.    your database.
  7411.  
  7412.    While the trunc. log on chkpt. option is set, you cannot dump the
  7413.    transaction log because the log is being truncated, and changes therefore
  7414.    are not recoverable from transaction log dumps. In this situation,
  7415.    executing the DUMP TRANSACTION statement produces an error message
  7416.    instructing you to use DUMP DATABASE instead.
  7417.  
  7418.    By default, the trunc. log on chkpt. option is off in newly created
  7419.    databases. To change the default, set this option in the model database.
  7420.  
  7421.  ────────────────────────────────────────────────────────────────────────────
  7422.  For a report on which database options are set in a particular database,
  7423.  execute the sp_helpdb system procedure in that database.
  7424.  
  7425.  Only the SA and Database Owner can change a user database's options by
  7426.  executing sp_dboption while using the master database. Then, for the change
  7427.  to take effect, the CHECKPOINT statement must be executed while using the
  7428.  database for which the option was changed.
  7429.  
  7430.  Remember that none of the master database's options can be changed.
  7431.  
  7432.  Here's how you'd use the read only option with sp_dboption to change the
  7433.  pubs database:
  7434.  
  7435.    use master
  7436.     <execute>
  7437.     sp_dboption pubs, "read only", true
  7438.     <execute>
  7439.     Execute the CHECKPOINT statement in the database that was changed.
  7440.     use pubs
  7441.     <execute>
  7442.     checkpoint
  7443.     <execute>
  7444.  
  7445.  For the optname parameter, SQL Server understands any unique string that is
  7446.  part of the option name. To set the trunc. log on chkpt. option, execute
  7447.  this statement:
  7448.  
  7449.    use master
  7450.     <execute>
  7451.     sp_dboption pubs, trunc, true
  7452.  
  7453.  If you enter a value for optname that is ambiguous, an error message is
  7454.  displayed. For example, two of the database options are dbo use only and
  7455.  read only. Using "only" for the optname parameter generates an error message
  7456.  because it matches both names. The complete names that match the supplied
  7457.  string are printed out so that you can see how to make the optname more
  7458.  specific.
  7459.  
  7460.  More than one database option can be set at a time.
  7461.  
  7462.  If you change a database option with sp_dboption inside a user-defined
  7463.  transaction and then roll back that transaction, you must execute a
  7464.  CHECKPOINT statement to make the rollback take effect. Here's an example:
  7465.  
  7466.    begin tran
  7467.     use master
  7468.     <execute>
  7469.     sp_dboption 'orderentry', 'single', 'true'
  7470.     <execute>
  7471.     use orderentry
  7472.     <execute>
  7473.     checkpoint
  7474.     <execute>
  7475.     rollback tran
  7476.     <execute>
  7477.     /*
  7478.     ** If the following checkpoint is not executed, the
  7479.     ** orderentry database remains single-user.
  7480.     */
  7481.     checkpoint
  7482.     <execute>
  7483.  
  7484.  
  7485.  Displaying Information on Database Options
  7486.  
  7487.  All users with access to the master database can execute sp_dboption with no
  7488.  parameters to display a list of database options. The report from
  7489.  sp_dboption looks like this:
  7490.  
  7491.    sp_dboption
  7492.  
  7493.     Settable database options.
  7494.     database_options
  7495.     --------------------
  7496.     ALL SETTABLE OPTIONS
  7497.     dbo use only
  7498.     no chkpt on recovery
  7499.     read only
  7500.     select into/bulkcopy
  7501.     single user
  7502.     trunc. log on chkpt.
  7503.  
  7504.     (7 rows affected)
  7505.  
  7506.  
  7507.  Monitoring SQL Server Activity
  7508.  
  7509.  SQL Server keeps track of how much work it has done in a series of
  7510.  predefined global variables. Global variables are distinguished from local
  7511.  variables by having two "at" signs (@) preceding their names, for example,
  7512.  @ERROR and @ROWCOUNT.
  7513.  
  7514.  You can query the global variables directly or execute sp_monitor to display
  7515.  the current values of some of these global variables and how much they have
  7516.  changed since the last time the procedure was executed.
  7517.  
  7518.  The sp_monitor system procedure takes no parameters. Here's how you use it
  7519.  and a sample report from it:
  7520.  
  7521.    sp_monitor
  7522.  
  7523.     last_run    current_run      seconds
  7524.     -------------------  -------------------------  -----------
  7525.     Jan 29 1987 10:11AM  Jan 29 1987 10:17AM    314
  7526.  
  7527.     cpu_busy    io_busy   idle
  7528.     --------------   ---------  -------------
  7529.     4250(215)-68%   67(1)-0%  109(100)-31%
  7530.  
  7531.     pack_received   pack_sent  packet_errors
  7532.     -------------   ------------ ----------------
  7533.     781(15)     10110(9596)  0(0)
  7534.  
  7535.     total_read    total_write  total_errors connections
  7536.     ------------   ------------- ------------- ------------
  7537.     394(67)     5392(53)  0(0)   15(1)
  7538.  
  7539.      (0 rows affected)
  7540.  
  7541.  For each column, the statistic is printed in the form number(number)-number%
  7542.  or number(number). The first number refers to the number of seconds (for
  7543.  cpu_busy, io_busy, and idle) or the total number (for the other variables)
  7544.  since SQL Server was restarted. The number in parentheses refers to the
  7545.  number of seconds or total number since the last time sp_monitor was
  7546.  executed. The percentage is the percent of time since sp_monitor was last
  7547.  executed.
  7548.  
  7549.  For example, this report shows cpu_busy as 4250(215)-68%. This means that
  7550.  the CPU has been busy 4250 seconds since SQL Server was last started and 215
  7551.  seconds since sp_monitor was last executed. The 68% means that the CPU has
  7552.  been busy 68% of the time since sp_monitor was last executed.
  7553.  
  7554.  For the total_read variable, the value 394(67) means there have been 394
  7555.  reads since SQL Server was restarted, 67 of them since the last time
  7556.  sp_monitor was run.
  7557.  
  7558.  The sp_monitor report has the following columns:
  7559.  
  7560.  ────────────────────────────────────────────────────────────────────────────
  7561.  last_run
  7562.    The clock time at which sp_monitor was last executed
  7563.  
  7564.  current_run
  7565.    The current clock time
  7566.  
  7567.  seconds
  7568.    The number of seconds since sp_monitor was last executed
  7569.  
  7570.  cpu_busy
  7571.    The number of milliseconds in CPU time that SQL Server's CPU was doing SQL
  7572.    Server work
  7573.  
  7574.  io_busy
  7575.    The number of milliseconds in CPU time that SQL Server has spent doing
  7576.    input and output operations
  7577.  
  7578.  idle
  7579.    The number of milliseconds in CPU time that SQL Server has been idle
  7580.  
  7581.  pack_received
  7582.    The number of input packets read by SQL Server
  7583.  
  7584.  pack_sent
  7585.    The number of output packets written by SQL Server
  7586.  
  7587.  packet_errors
  7588.    The number of errors detected by SQL Server while reading and writing
  7589.    packets
  7590.  
  7591.  total_read
  7592.    The number of disk reads by SQL Server
  7593.  
  7594.  total_write
  7595.    The number of disk writes by SQL Server
  7596.  
  7597.  total_errors
  7598.    The number of errors detected by SQL Server while reading and writing
  7599.  
  7600.  connections
  7601.    The number of logins or attempted logins to SQL Server
  7602.  
  7603.  ────────────────────────────────────────────────────────────────────────────
  7604.  With the exception of last_run, current_run, and seconds, all these column
  7605.  headings are also the names of global variables─except that all global
  7606.  variables are preceded by @. There is also a difference in the units of the
  7607.  numbers reported by the global variables; the numbers reported by the global
  7608.  variables are not milliseconds of CPU time, but ticks. Each tick on MS OS/2
  7609.  is 31.25 milliseconds (1/32 second).
  7610.  
  7611.  Here's how you'd query a global variable directly:
  7612.  
  7613. ╓┌───────────────────┌───────────────────────────────────────────────────────╖
  7614.  ────────────────────────────────────────────────────────────────────────────
  7615.                      select @cpu_busy
  7616.  
  7617.                      ------------
  7618.                      4250
  7619.  
  7620.                      (1 row affected)
  7621.  
  7622.  
  7623.  There are some other global variables whose values are not reported by
  7624.  sp_monitor. They are as follows:
  7625.  
  7626.  ────────────────────────────────────────────────────────────────────────────
  7627.  @@ERROR
  7628.    The last return code generated by your process. The @ERROR global variable
  7629.    is commonly used to check the error status (succeeded or failed) of the
  7630.    most recently executed statement. A statement such as "if @error != 0
  7631.    return" would cause an exit if an error had occurred.
  7632.  
  7633.  @@ROWCOUNT
  7634.    The number of rows affected by your last statement.
  7635.  
  7636.  @@PROCID
  7637.    The stored procedure ID of the currently executing procedure.
  7638.  
  7639.  @@NESTLEVEL
  7640.    The nesting level of the current execution (initially zero). Each time a
  7641.    stored procedure calls another stored procedure, the nesting level is
  7642.    incremented. If the maximum of 32 is exceeded, the transaction aborts.
  7643.  
  7644.  @@VERSION
  7645.    The date of the current version of SQL Server.
  7646.  
  7647.  @@TRANCOUNT
  7648.    The number of currently active transactions for the current user.
  7649.  
  7650.  @@TIMETICKS
  7651.    The number of microseconds per tick.
  7652.  
  7653.  @@MAX_CONNECTIONS
  7654.    The maximum number of simultaneous connections that can be made with SQL
  7655.    Server in this computer environment. The user can configure SQL Server for
  7656.    fewer connections with sp_configure.
  7657.  
  7658.  @@TEXTSIZE
  7659.    The size (in bytes) of text or image data to be returned with a SELECT
  7660.    statement.
  7661.  
  7662.  ────────────────────────────────────────────────────────────────────────────
  7663.  Any user can query the global variables. However, only the SA can execute
  7664.  sp_monitor because the procedure updates a table in the master database
  7665.  called spt_monitor.
  7666.  
  7667.  
  7668.  Updating Statistics
  7669.  
  7670.  The UPDATE STATISTICS statement helps SQL Server make the best decisions
  7671.  about which indexes to use when it processes a query by keeping it up to
  7672.  date about the distribution of the key values in the indexes. You should use
  7673.  this statement when you create an index on already existing data or when a
  7674.  large amount of data in an indexed column has been added, changed, or
  7675.  deleted.
  7676.  
  7677.  Permission to execute the UPDATE STATISTICS statement defaults to the table
  7678.  owner and cannot be transferred. The UPDATE STATISTICS statement has the
  7679.  following syntax:
  7680.  
  7681.    UPDATE STATISTICS table_name [index_name]
  7682.  
  7683.  If you do not specify an index name, the statement updates the distribution
  7684.  statistics for all the indexes in the specified table. Giving an index name
  7685.  updates statistics for that index only.
  7686.  
  7687.  You can find the name of the indexes by using the sp_helpindex system
  7688.  procedure. This procedure takes a table name as a parameter.
  7689.  
  7690.  To list the indexes for the authors table and then update the statistics for
  7691.  all of the indexes in the table, type
  7692.  
  7693.    sp_helpindex authors
  7694.     update statistics authors
  7695.  
  7696.  To update the statistics for the index on the au_id column only, type
  7697.  
  7698.    update statistics authors auidind
  7699.  
  7700.  Since TRANSACT-SQL does not require index names to be unique in a database,
  7701.  you must give the name of the table with which the index is associated.
  7702.  
  7703.  
  7704.  Locking and the HOLDLOCK Keyword
  7705.  
  7706.  To prevent other users from interfering with data being used for an active
  7707.  transaction, SQL Server protects the relevant tables or data pages of the
  7708.  database by locking them. Locking is a concurrency control mechanism. It is
  7709.  necessary in a multiuser environment since several users may be working with
  7710.  the same data at the same time.
  7711.  
  7712.  SQL Server handles locking decisions on its own. It always applies exclusive
  7713.  locks for data modification operations (UPDATE, INSERT, or DELETE). When an
  7714.  exclusive lock is set, no other transaction can acquire a lock of any kind
  7715.  on those objects until the original lock is released at the end of the
  7716.  transaction. The data modification statements are sometimes called "write"
  7717.  operations because they add, remove, or modify data.
  7718.  
  7719.  For nonupdate or "read" operations, such as SELECT, SQL Server applies
  7720.  shared locks. If a shared lock has been applied to a table or data page,
  7721.  other transactions can also acquire a shared lock even though the first
  7722.  transaction hasn't completed. However, no transaction can acquire an
  7723.  exclusive lock until all shared locks on it have been released. That is,
  7724.  many transactions can simultaneously read the table or page, but no one can
  7725.  write to it.
  7726.  
  7727.  Conversely, if a transaction has an exclusive lock, another transaction
  7728.  can't acquire a shared lock on it. Exclusive locks and shared locks can be
  7729.  applied either at the table level or at the page level─a data page or a leaf
  7730.  page of an index.
  7731.  
  7732.  
  7733.  Displaying Information on Locking
  7734.  
  7735.  To get a report on the locks currently being held on SQL Server, use the
  7736.  sp_lock system procedure:
  7737.  
  7738. ╓┌─┌──────────────────┌──────────┌───────────┌──────┌────────────────────────╖
  7739.  ────────────────────────────────────────────────────────────────────────────
  7740.    sp_lock
  7741.  
  7742.    spid               locktype   table_id    page   dbname
  7743.    ------             ---------  ----------  -----  ----------
  7744.    1                  Sh_intent  16003088    0      master
  7745.    4                  Ex_extent  0           440    pubs
  7746.    4                  Ex_extent  0           504    pubs
  7747.    4                  Sh_table   112003430   0      pubs
  7748.    4                  Ex_table   240003886   0      pubs
  7749.  
  7750.    (5 rows affected)
  7751.  ────────────────────────────────────────────────────────────────────────────
  7752.   (5 rows affected)
  7753.  
  7754.  
  7755.  The locktype column indicates not only whether the lock is a shared lock
  7756.  (Sh) or an exclusive lock (Ex), but also whether it is held on a table or a
  7757.  page, and whether it is an intent lock, an extent lock, or a demand lock.
  7758.  
  7759.  An intent lock indicates the intention to acquire a shared or exclusive lock
  7760.  on a data page. Setting an intent lock prevents another transaction from
  7761.  subsequently acquiring an exclusive lock on the table that contains that
  7762.  page.
  7763.  
  7764.  An extent lock is a lock held on a group of eight database pages while they
  7765.  are being allocated or freed. Extent locks are set while a CREATE or DROP
  7766.  statement is executing, or while an INSERT operation that requires new data
  7767.  or index pages is running.
  7768.  
  7769.  A demand lock prevents any more shared locks from being set. It indicates
  7770.  that a transaction is next in line to lock a table or page. Demand locks are
  7771.  necessary because shared locks can overlap so that read transactions keep
  7772.  monopolizing a table or page, forcing a write transaction to wait
  7773.  indefinitely. After waiting on four different read transactions, a write
  7774.  transaction is given a demand lock. As soon as the existing read
  7775.  transactions finish, the write transaction is allowed to proceed. Any new
  7776.  read transactions will then have to wait for the write transaction to finish
  7777.  and release its exclusive lock.
  7778.  
  7779.  Advanced users may want to query the syslocks system table for additional
  7780.  information on locks. See Appendix B, "System Tables," for a description of
  7781.  this table.
  7782.  
  7783.  
  7784.  HOLDLOCK Keyword
  7785.  
  7786.  The HOLDLOCK keyword, used after a table name or view name in the FROM
  7787.  clause of a SELECT statement, makes a shared lock more restrictive. It
  7788.  applies only to shared locks, only to the table or view for which it is
  7789.  specified, and only for the duration of the transaction defined by the
  7790.  statement in which it is used.
  7791.  
  7792.  HOLDLOCK instructs SQL Server to hold the shared lock that it has set until
  7793.  the completion of the transaction, instead of releasing it as soon as the
  7794.  required table, view, or data page is no longer needed, whether or not the
  7795.  transaction has been completed.
  7796.  
  7797.  SQL Server's normal handling of shared locks─releasing them as soon as the
  7798.  table, view, or data page is no longer needed─allows continued interactive
  7799.  use of the database even while a lengthy transaction is proceeding. However,
  7800.  it also means that if the same entry is read twice within the same
  7801.  transaction, it won't necessarily be the same both times.
  7802.  
  7803.  
  7804.  Deadlocks and Livelocks
  7805.  
  7806.  SQL Server automatically detects and resolves both deadlocks and livelocks.
  7807.  
  7808.  
  7809.  A deadlock occurs when two users each have a lock on a separate object. Each
  7810.  wants to acquire an additional lock on the other user's object. When this
  7811.  happens, the first user is waiting for the second to let go of the lock, but
  7812.  the second user won't let it go until the lock on the first user's object is
  7813.  freed.
  7814.  
  7815.  SQL Server detects this situation and chooses one of the users. SQL Server
  7816.  rolls back that user's transaction, notifies the application program of this
  7817.  action with message number 1205, and allows the other user's processes to
  7818.  move forward. The first user's process is killed and everything starts
  7819.  moving.
  7820.  
  7821.  In a multiuser situation, each user's application program should check every
  7822.  transaction for message 1205. It indicates that the user was chosen for a
  7823.  deadlock. The application program must restart that transaction.
  7824.  
  7825.  It is possible to encounter a deadlock when several long-running
  7826.  transactions are being executed at the same time in the same database.
  7827.  
  7828.  In a livelock, a request for an exclusive lock is repeatedly denied because
  7829.  a series of overlapping shared locks keeps interfering.
  7830.  
  7831.  SQL Server detects this situation, too. After four denials to the user
  7832.  requesting the exclusive lock (who has been assigned a demand lock), SQL
  7833.  Server refuses further requests from shared locks. The request for the
  7834.  exclusive lock is then granted without noticeable effect on the application.
  7835.  
  7836.  
  7837.  
  7838.  Setting Configuration Options
  7839.  
  7840.  The configuration options control various aspects of SQL Server's memory
  7841.  allocation and performance. The SA can reset these configuration options to
  7842.  fine-tune performance and refine storage allocation. The setup program
  7843.  adjusts the amount of memory available to SQL Server and the total number of
  7844.  users, based on the amount of memory in your computer. The setup program
  7845.  assumes the following:
  7846.  
  7847.  
  7848.    ■   An application in which there is a great deal of update activity
  7849.  
  7850.    ■   An application in which a relatively small number of stored procedures
  7851.        are used repeatedly
  7852.  
  7853.  
  7854.  If your application differs significantly from these assumptions, you may
  7855.  reset the configuration options to improve performance. You should also
  7856.  change the configuration options if you change the amount of memory in your
  7857.  computer.
  7858.  
  7859.  
  7860.  Configuration Options
  7861.  
  7862.  The following sections describe each of the configuration options.
  7863.  
  7864.  
  7865.  Recovery Interval
  7866.  
  7867.  The recovery_interval configuration option sets the maximum number of
  7868.  minutes per database that SQL Server needs to complete its recovery
  7869.  procedures in case of a system failure.
  7870.  
  7871.  The default value for this option is 5 (minutes per database).
  7872.  
  7873.  SQL Server uses this number and the amount of activity on each database to
  7874.  decide when to do a checkpoint on each database. When SQL Server does a
  7875.  checkpoint, it writes all dirty pages (data pages that have been changed by
  7876.  data modification statements) to the disk. The checkpoint also performs a
  7877.  few other "housekeeping" tasks, including truncating the log if this option
  7878.  has been set with sp_dboption. A typical checkpoint takes about one second.
  7879.  
  7880.  
  7881.  You may want to change the recovery interval as your application and its
  7882.  usage change. For example, to guarantee that changes are frequently written
  7883.  to the disk, you may want to shorten the recovery interval when there is a
  7884.  lot of update activity on SQL Server. Shortening the recovery interval
  7885.  causes more frequent checkpoints, which slows the system very slightly. On
  7886.  the other hand, setting the recovery interval too high might cause the
  7887.  recovery time to be unacceptably long.
  7888.  
  7889.  This option is one of the two dynamic ones, which means that an updated
  7890.  value takes effect as soon as the SA executes the RECONFIGURE statement.
  7891.  
  7892.  
  7893.  Allow Updates
  7894.  
  7895.  By default, system tables can be updated only indirectly with system
  7896.  procedures or the SAF menus. The allow updates configuration option allows
  7897.  the SA to change this.
  7898.  
  7899.  The allow updates option is either on or off. When the value is changed from
  7900.  the default 0 (off) to 1 (on), any user with appropriate permissions can
  7901.  update the system tables directly with ad hoc queries and can create stored
  7902.  procedures that update the system tables.
  7903.  
  7904.  ────────────────────────────────────────────────────────────────────────────
  7905.  WARNING
  7906.  
  7907.  Updating certain fields in the system tables prevents SQL Server from
  7908.  running. Therefore, allowing direct updates to the system tables is risky.
  7909.  Stored procedures that are created while the allow updates option is on will
  7910.  always be able to update the system tables, even after the option has been
  7911.  turned off. Whenever you turn the allow updates option on, you are creating
  7912.  a "window of vulnerability"─a period of time during which SQL Server users
  7913.  can alter the system tables or create a stored procedure with which the
  7914.  system tables can be altered in the future.
  7915.  ────────────────────────────────────────────────────────────────────────────
  7916.  
  7917.  Because the system tables are so critical, it is best to turn this option on
  7918.  only in highly controlled situations. If you want to guarantee that no other
  7919.  users can access SQL Server while the system tables can be directly updated,
  7920.  you can restart SQL Server with
  7921.  
  7922.    sqlservr /m
  7923.  
  7924.  This option starts SQL Server in a single-user mode, which allows only one
  7925.  SA to log in, and turns on the allow updates configuration option. For
  7926.  details, see the SQL Server Language Reference.
  7927.  
  7928.  The allow updates option is a dynamic option, which means that a new value
  7929.  takes effect as soon as the SA executes the RECONFIGURE WITH OVERRIDE
  7930.  statement. The WITH OVERRIDE clause is always required for this
  7931.  configuration option as an added measure of protection.
  7932.  
  7933.  
  7934.  User Connections
  7935.  
  7936.  The user connections configuration option sets the maximum number of
  7937.  simultaneous connections─user and background processes─to SQL Server. It
  7938.  does not refer to the maximum number of users; that number depends not only
  7939.  on the value of this option but also on other system activity.
  7940.  
  7941.  The maximum number of connections is 250. The effective number is based upon
  7942.  your system configuration and is stored in the global variable
  7943.  @MAX_CONNECTIONS. You can get a report on the maximum number of file
  7944.  descriptors that your system can use with this statement:
  7945.  
  7946.    select @max_connections
  7947.  
  7948.  The memory overhead per connection is 40K.
  7949.  
  7950.  There is no formula for determining how many connections to allow for each
  7951.  user. Rather, you must estimate this number based on the system and user
  7952.  requirements outlined here. You must also take into account that on a system
  7953.  with many users, there is more likelihood that connections needed only
  7954.  occasionally can be shared among users.
  7955.  
  7956.  The following user connections are required:
  7957.  
  7958.  
  7959.    ■   Each user who runs a utility program simultaneously with another user
  7960.        needs one connection.
  7961.  
  7962.    ■   Application developers use one connection for each editing session.
  7963.        The number of connections required by users running an application
  7964.        depends entirely on how the application has been programmed.
  7965.  
  7966.    ■   Users writing DB-LIBRARY programs need one connection for each call to
  7967.        dbopen.
  7968.  
  7969.        In addition to the connections required for users, SQL Server needs a
  7970.        number of connections for system activity: a minimum of five
  7971.        connections must be reserved for such things as error logging, access
  7972.        to the master database, and listening to the network.
  7973.  
  7974.    ■   In addition to the connection used by the master database device, a
  7975.        connection is opened and permanently allocated for each additional
  7976.        database device when SQL Server is started or when the database device
  7977.        is initialized.
  7978.  
  7979.    ■   Each dump device needs one connection, but only while a dump or load
  7980.        is in progress.
  7981.  
  7982.    ■   In addition to the connection required for the console utility's
  7983.        network pipe, a new connection is created for reading and writing when
  7984.        the console utility is started.
  7985.  
  7986.  
  7987.  It's a good idea to figure out the maximum number of connections that will
  7988.  be used by SQL Server and to keep this number in mind as you add physical
  7989.  devices or users to the system.
  7990.  
  7991.  
  7992.  Memory
  7993.  
  7994.  The memory configuration option sets the size of available memory in 2K
  7995.  units. The default run value is set by the setup program based on the amount
  7996.  of memory in your computer.
  7997.  
  7998.  To optimize this number for your system, subtract the memory required for MS
  7999.  OS/2 in the network (and other system uses, if the machine is not wholly
  8000.  dedicated to SQL Server) from the total physical memory.
  8001.  
  8002.  The amount of memory specified must be sufficient for SQL Server's static
  8003.  memory needs (kernel overhead, user stack space, and so on), as well as for
  8004.  the procedure cache and the data cache (also called buffer cache). The
  8005.  caches are discussed later.
  8006.  
  8007.  The memory left over after SQL Server's memory needs are met is divided
  8008.  between the procedure cache and the data cache. The percentage allocated to
  8009.  the procedure cache is set by the procedure cache configuration option.
  8010.  
  8011.  Change this value only when you add or remove memory, or when the use of the
  8012.  computer system changes.
  8013.  
  8014.  
  8015.  Open Databases
  8016.  
  8017.  The open database configuration option sets the maximum number of databases
  8018.  that can be open at one time on SQL Server.
  8019.  
  8020.  The default value is 10. Setting the number of open databases higher does
  8021.  not have a significant impact on performance or storage requirements.
  8022.  Therefore, don't hesitate to increase this value if SQL Server displays a
  8023.  message saying that you've exceeded the allowable number of open databases.
  8024.  
  8025.  
  8026.  
  8027.  Locks
  8028.  
  8029.  The locks configuration option sets the number of available locks. Locks are
  8030.  not shared the way open databases and database objects are.
  8031.  
  8032.  The default value is 5000. Increase this value if SQL Server displays a
  8033.  message saying that you have exceeded the number of available locks. Since
  8034.  locks consume memory, increasing this value may make it necessary to
  8035.  increase the amount of memory dedicated to the server.
  8036.  
  8037.  
  8038.  Open Objects
  8039.  
  8040.  The open objects configuration option sets the maximum number of database
  8041.  objects that can be open at one time on SQL Server.
  8042.  
  8043.  The default value is 300. Increase this value if SQL Server displays a
  8044.  message saying that you have exceeded the number of open objects. Since open
  8045.  objects consume memory, increasing this value may make it necessary to
  8046.  increase the amount of memory dedicated to the server.
  8047.  
  8048.  
  8049.  Procedure Cache
  8050.  
  8051.  The procedure cache configuration option gives the percentage of memory
  8052.  allocated to the procedure cache after SQL Server's memory needs are met.
  8053.  SQL Server's memory needs are the sum of memory necessary for locks, user
  8054.  connections, the code itself (which varies slightly from release to
  8055.  release), and so on. The remaining memory is divided between the procedure
  8056.  cache and the data cache according to the percentage given by this
  8057.  configuration option.
  8058.  
  8059.  The procedure cache is the area of memory where the most recently used
  8060.  procedures are stored. The procedure cache is also used when a procedure is
  8061.  being created and when a query is being compiled. If SQL Server finds a
  8062.  procedure or a compilation already in the cache, it isn't necessary to read
  8063.  it from the disk.
  8064.  
  8065.  The data cache is the area of memory where the most recently used data pages
  8066.  and index pages are stored. If SQL Server finds a data page or index page
  8067.  that has already been called by a user in the cache, it isn't necessary to
  8068.  read it from the disk.
  8069.  
  8070.  Both caches are managed in an LRU-MRU (least recently used, most recently
  8071.  used) fashion.
  8072.  
  8073.  The default value for this configuration option is 20, which gives the
  8074.  procedure cache 20% of the remaining memory after SQL Server's requirements
  8075.  are met. By default, the data cache gets the other 80%.
  8076.  
  8077.  Since the optimum value for this configuration option is different from
  8078.  application to application, resetting it may improve SQL Server's
  8079.  performance. For example, if you run a lot of different procedures or ad hoc
  8080.  queries, your application will use the procedure cache more heavily, so you
  8081.  may want to increase this value.
  8082.  
  8083.  Many applications fall in this category while they are being developed. You
  8084.  may want to try setting this option to 50 during your development cycle and
  8085.  then resetting it to 20 when your application has stabilized.
  8086.  
  8087.  
  8088.  Fill Factor
  8089.  
  8090.  The fill factor configuration option determines how full SQL Server makes
  8091.  each page when it is creating a new index on existing data (unless the user
  8092.  specifies some other value in the CREATE INDEX statement). The fill factor
  8093.  percentage affects performance because SQL Server must take the time to
  8094.  split pages when they fill up.
  8095.  
  8096.  The fill factor percentage is used only at the time the index is created and
  8097.  becomes less important as changes to the data are made. The pages are not
  8098.  maintained at any particular level of fullness.
  8099.  
  8100.  The default fill factor value is 0; legal values are 0 to 100. A fill factor
  8101.  of 0 does not mean that pages are 0% full. Rather, it is treated like a fill
  8102.  factor of 100 in that SQL Server creates clustered indexes with full data
  8103.  pages and nonclustered indexes with completely full leaf pages. It is
  8104.  different from 100 in that SQL Server leaves a comfortable amount of space
  8105.  within the index B-tree in both cases. There is seldom a reason to change
  8106.  the fill factor option, especially since you can override it in the CREATE
  8107.  INDEX statement.
  8108.  
  8109.  If the fill factor is set to 100, SQL Server creates both clustered and
  8110.  nonclustered indexes with each page 100% full. A fill factor of 100 makes
  8111.  sense only for read-only tables─tables to which no additional data will ever
  8112.  be added.
  8113.  
  8114.  Smaller fill factor values cause SQL Server to create new indexes with pages
  8115.  that are not full. For example, a fill factor of 10 might be a reasonable
  8116.  choice if you are creating an index on a table that you know contains a
  8117.  small portion of the data it will eventually hold. Smaller fill factor
  8118.  values cause each index to take more storage space.
  8119.  
  8120.  
  8121.  Time Slice
  8122.  
  8123.  The time slice configuration option sets the number of milliseconds that a
  8124.  user process is allowed to run by SQL Server's scheduler (which is invisible
  8125.  to the user). If the time slice is set too low, SQL Server may spend too
  8126.  much time switching processes. If it is set too high, users may experience
  8127.  long response time.
  8128.  
  8129.  The default value is 100 milliseconds. There is seldom reason to change it.
  8130.  
  8131.  
  8132.  
  8133.  Database Size
  8134.  
  8135.  The database size configuration option sets the default number of megabytes
  8136.  allocated to each new user database. A database size given in a CREATE
  8137.  DATABASE statement takes precedence over the value set by this configuration
  8138.  option.
  8139.  
  8140.  The default value is 2 (megabytes). If most of the new databases on your SQL
  8141.  Server require more than 2 megabytes you may want to increase this value.
  8142.  You must increase it if your model database grows to be larger than 2
  8143.  megabytes, since the CREATE DATABASE statement causes SQL Server to copy
  8144.  model to create a new user database.
  8145.  
  8146.  
  8147.  Media Retention
  8148.  
  8149.  The media retention configuration option can be used to set the number of
  8150.  days that you expect to retain each diskette after it has been used for a
  8151.  database or transaction log dump. If you try to use the diskette before that
  8152.  many days have passed, SQL Server issues a warning message. You can override
  8153.  the warning if you wish.
  8154.  
  8155.  The default value is 0. Unless you change it, no warning is issued. A
  8156.  typical value might be 7 (days).
  8157.  
  8158.  
  8159.  Recovery Flags
  8160.  
  8161.  The recovery flags configuration option determines what information SQL
  8162.  Server displays on the console during recovery. The default value is 0,
  8163.  which means that SQL Server displays only the database name and a message
  8164.  saying that recovery is in progress. The other legal value is 1, which means
  8165.  that SQL Server displays information about each individual transaction,
  8166.  including whether it was aborted or committed.
  8167.  
  8168.  
  8169.  Serial Number
  8170.  
  8171.  The serial number option is reserved for future use.
  8172.  
  8173.  
  8174.  Changing Configuration Options Using the Config Menu
  8175.  
  8176.  You can easily change the configuration options using the Config menu. The
  8177.  SAF groups these options into three categories:
  8178.  
  8179.  
  8180.    ■   Memory options
  8181.  
  8182.        ■   User connections
  8183.  
  8184.        ■   Memory
  8185.  
  8186.        ■   Procedure cache
  8187.  
  8188.  
  8189.    ■   General options
  8190.  
  8191.        ■   Open databases
  8192.  
  8193.        ■   Time slice
  8194.  
  8195.        ■   Open objects
  8196.  
  8197.        ■   Database size
  8198.  
  8199.        ■   Locks
  8200.  
  8201.        ■   Media retention
  8202.  
  8203.        ■   Fill factor
  8204.  
  8205.        ■   Recovery flags
  8206.  
  8207.  
  8208.    ■   Dynamic options
  8209.  
  8210.        ■   Recovery interval
  8211.  
  8212.        ■   Allow updates
  8213.  
  8214.  After changing values for the memory and general configuration options, you
  8215.  have to shut down and restart SQL Server before these new values will take
  8216.  effect. The dynamic options take effect immediately.
  8217.  
  8218.  
  8219.  
  8220.  Changing Memory and General Configuration Options
  8221.  
  8222.  To change memory and general configuration options:
  8223.  
  8224.  
  8225.    1.  Select the Config menu and choose the appropriate menu item, depending
  8226.        on which option you want to change.
  8227.  
  8228.        The appropriate dialog box appears. The range of values for each
  8229.        option is shown to the far right of the option. The text box where you
  8230.        place the desired value is to the immediate right of the option.
  8231.  
  8232.    2.  Enter the new value in the text box.
  8233.  
  8234.    3.  Choose OK.
  8235.  
  8236.        After you change the Memory and General configuration options with the
  8237.        SAF, you must shut down and restart SQL Server before these new
  8238.        options take effect.
  8239.  
  8240.  
  8241.  
  8242.  Changing Dynamic Configuration Options
  8243.  
  8244.  To change dynamic configuration options:
  8245.  
  8246.  
  8247.    1.  Select the Config menu and choose Dynamic Options.
  8248.  
  8249.        The "Dynamic Options" dialog box appears. The range of values for each
  8250.        option is shown to the far right of the option. The text box where you
  8251.        place the desired value is to the immediate right of the option.
  8252.  
  8253.    2.  Enter the new value in the text box.
  8254.  
  8255.    3.  Choose OK.
  8256.  
  8257.        The configuration option takes effect immediately. You do not have to
  8258.        restart SQL Server.
  8259.  
  8260.  
  8261.  
  8262.  Changing Configuration Options Using System Procedures
  8263.  
  8264.  To reset the configuration options:
  8265.  
  8266.  
  8267.    1.  Execute the sp_configure system procedure.
  8268.  
  8269.    2.  Execute the RECONFIGURE statement.
  8270.  
  8271.    3.  Restart SQL Server if dynamic configuration options have been changed.
  8272.  
  8273.  
  8274.  The sp_configure system procedure has the following syntax:
  8275.  
  8276.    sp_configure [configname [, configvalue]]
  8277.  
  8278.  ────────────────────────────────────────────────────────────────────────────
  8279.  configname
  8280.  
  8281.    The name of the configuration option
  8282.  
  8283.  configvalue
  8284.    The value for the configuration option
  8285.  
  8286.  ────────────────────────────────────────────────────────────────────────────
  8287.  The most frequently changed configuration options are as follows:
  8288.  
  8289.  
  8290.    ■   User connections
  8291.  
  8292.    ■   Memory
  8293.  
  8294.    ■   Procedure cache
  8295.  
  8296.  
  8297.  Here's how you would increase the number of user connections:
  8298.  
  8299.    sp_configure "user conn", 30
  8300.  
  8301.  After executing sp_configure, execute the RECONFIGURE statement. The
  8302.  RECONFIGURE statement has the following syntax:
  8303.  
  8304.    RECONFIGURE [WITH OVERRIDE]
  8305.  
  8306.  Only the SA has permission to use the RECONFIGURE statement. It cannot be
  8307.  transferred to other users.
  8308.  
  8309.  When the SA executes the RECONFIGURE statement, SQL Server checks to make
  8310.  sure that the new values in sysconfigures are acceptable and reasonable.
  8311.  
  8312.  User-supplied values that seem unreasonable to SQL Server cause it to abort
  8313.  the RECONFIGURE statement and display a warning message. The SA can then
  8314.  re-execute sp_configure with a new value, or re-execute the RECONFIGURE
  8315.  statement with the WITH OVERRIDE clause, which causes SQL Server to accept
  8316.  whatever values the SA supplies.
  8317.  
  8318.  One of the configuration options, allow updates, always requires RECONFIGURE
  8319.  WITH OVERRIDE. This requirement is meant to supply a small measure of added
  8320.  precaution─to cause the SA to consider the consequences of allowing direct
  8321.  updates to the system tables.
  8322.  
  8323.  For any values set to zero, SQL Server calculates a default. For example, if
  8324.  the user gives 0 for the number of open databases, SQL Server might
  8325.  substitute the value 10.
  8326.  
  8327.  When the RECONFIGURE statement is accepted, SQL Server writes the new
  8328.  configuration options to the area of the disk that holds the configuration
  8329.  structure. Then it updates any of the dynamic options (recovery interval or
  8330.  allow updates) that were changed. These dynamic configuration changes take
  8331.  effect immediately.
  8332.  
  8333.  None of the nondynamic configuration options (everything except recovery
  8334.  interval and allow updates) takes effect until the next time SQL Server is
  8335.  restarted.
  8336.  
  8337.  
  8338.  Displaying Information on Configuration Options
  8339.  
  8340.  To get a report on current settings of configuration options, use the SAF
  8341.  Config menu:
  8342.  
  8343.  
  8344.    1.  Choose the Config menu.
  8345.  
  8346.    2.  Choose Memory Options, General Options, or Dynamic Options.
  8347.  
  8348.        A dialog box appears. Current settings of each configuration option
  8349.        are displayed immediately to the right of the option name. The range
  8350.        of values allowed for each option is displayed to the right of the
  8351.        current setting.
  8352.  
  8353.  
  8354.  Advanced users may want to query the sysconfigures and syscurconfigs system
  8355.  tables for additional information on configuration options. See Appendix B,
  8356.  "System Tables," for a description of these tables.
  8357.  
  8358.  
  8359.  
  8360.  
  8361.  
  8362.  
  8363.  Chapter 10  Transferring Data to and from SQL Server
  8364.  ────────────────────────────────────────────────────────────────────────────
  8365.  
  8366.  
  8367.  Introduction
  8368.  
  8369.  This chapter explains how to move data between SQL Server and an operating
  8370.  system file or a diskette. There are two direct ways to accomplish this:
  8371.  
  8372.  
  8373.    ■   With the bulk copy utility program, bcp, used as a stand-alone program
  8374.        from the operating system
  8375.  
  8376.    ■   With DB-LIBRARY functions from inside an application program
  8377.  
  8378.  
  8379.  This chapter discusses data transfer with bcp. For information about
  8380.  DB-LIBRARY, see the SQL Server Programmer's Reference.
  8381.  
  8382.  There are no SQL commands for the bulk transfer of data.
  8383.  
  8384.  The bcp program is most frequently used to transfer into a database data
  8385.  that was previously associated with another program, usually another
  8386.  database management system. The data to be transferred must be put into an
  8387.  operating system file or onto diskette with some kind of dump facility
  8388.  provided by the old program.
  8389.  
  8390.  The bcp program can also be used for temporary transfers of data for use
  8391.  with other programs─for example, with spreadsheet programs. The data is
  8392.  moved from SQL Server into an operating system file or onto diskette; from
  8393.  there, the other program can import the data. When you are through using
  8394.  your data with the other program, it can be transferred back into an
  8395.  operating system file or onto diskette and then back into SQL Server with
  8396.  bcp.
  8397.  
  8398.  SQL Server can accept data in any ASCII or binary format if you can describe
  8399.  the terminators (the characters used to separate columns). The table
  8400.  structures need not be identical. Data copied into SQL Server is appended to
  8401.  any existing contents of a table; data copied out to a file overwrites any
  8402.  previous contents of the file.
  8403.  
  8404.  To use bcp, you must have an SQL Server account and the appropriate
  8405.  permissions on the database tables and operating system files. To copy data
  8406.  out of a table, you must have SELECT permission on that table; to copy data
  8407.  into a table, you must have INSERT permission on the table.
  8408.  
  8409.  In general, you must supply the following information for transferring data
  8410.  to and from SQL Server:
  8411.  
  8412.  
  8413.    ■   The name of the database and table
  8414.  
  8415.    ■   The name of the operating system file or diskette drive
  8416.  
  8417.    ■   The direction of the transfer (in or out)
  8418.  
  8419.  
  8420.  In addition, for each column, you can optionally modify the datatype,
  8421.  length, and terminator.
  8422.  
  8423.  
  8424.  Permissions Needed to Copy Data
  8425.  
  8426.  To copy data from an operating system file into a table, the user must have
  8427.  INSERT permission on the table.
  8428.  
  8429.  To copy a table out to an operating system file, the user must have SELECT
  8430.  permission on the following tables:
  8431.  
  8432.  
  8433.    ■   The table being copied
  8434.  
  8435.    ■   sysobjects
  8436.  
  8437.    ■   syscolumns
  8438.  
  8439.    ■   sysindexes
  8440.  
  8441.  
  8442.  
  8443.  Transferring Data with the Bulk Copy Utility
  8444.  
  8445.  The bcp program transfers data between an existing database table and an
  8446.  operating system file in a format that can be specified by the user, and is
  8447.  executed from the operating system.
  8448.  
  8449.  The bcp program has the following syntax:
  8450.  
  8451.    bcp [[database_name.]owner.]table_name {in | out} datafile
  8452.     [/m maxerrors] [/f formatfile] [/e errfile]
  8453.     [/F firstrow] [/L lastrow] [/b batchsize]
  8454.     [/n native_type] [/c character_type]
  8455.     [/t field_term] [/r row_term]
  8456.     [/i input_file] [/o output_file]
  8457.     [/U login_id] [/P password]
  8458.     [/I interface] [/S servername]
  8459.     [/v version]
  8460.  
  8461.  ────────────────────────────────────────────────────────────────────────────
  8462.  database_name
  8463.    The database name, which is optional if the table being copied is in your
  8464.    default database. Otherwise, you must specify a database name.
  8465.  
  8466.  owner
  8467.    The owner's name, which is optional only if you own the table being
  8468.    copied. If no owner is specified and you do not own a table of that name,
  8469.    the bulk copy will fail.
  8470.  
  8471.  table_name
  8472.    The name of the database table you want to copy.
  8473.  
  8474.  in, out
  8475.    The direction of the copy. The in option is a copy from a file into the
  8476.    database table, while the out option is a copy to a file from the database
  8477.    table.
  8478.  
  8479.  datafile
  8480.    The full pathname of an operating system file. The pathname can be from 1
  8481.    to 255 characters in length. It can also indicate a diskette drive name.
  8482.  
  8483.  /m maxerrors
  8484.    The maximum number of errors before the copy is aborted. Each row that
  8485.    can't be rebuilt by bcp is thrown out and counted as one error. The
  8486.    default used if this option is not included is 10.
  8487.  
  8488.  /f formatfile
  8489.    The full pathname of a file with stored responses from a previous use of
  8490.    bcp on the same table; creation of the format file is optional. Use this
  8491.    option when you have already created a format file that you want to use
  8492.    for a copy in or out. After you answer bcp's format questions, it will ask
  8493.    you if you want to save your answers in a format file. The default
  8494.    filename is bcp.fmt. The bcp program can refer to a format file when
  8495.    copying data so that you do not have to duplicate your previous format
  8496.    responses interactively. If this option is not used, bcp queries you for
  8497.    format information interactively.
  8498.  
  8499.  /e errfile
  8500.    The full pathname of an error file where bcp stores any rows that it was
  8501.    unable to transfer from the file to the database. Error messages from the
  8502.    bcp program go to the user's workstation. If this option is not used, no
  8503.    error file is created.
  8504.  
  8505.  /F firstrow
  8506.    The number of the first row to copy (the default is the first row).
  8507.  
  8508.  /L lastrow
  8509.    The number of the last row to copy (the default is the last row).
  8510.  
  8511.  /b batchsize
  8512.    The number of rows per batch of data copied (the default copies all the
  8513.    rows in one batch).
  8514.  
  8515.  /n native_type
  8516.    Performs the copy operation using the data's native (database) datatypes
  8517.    as the defaults. This option does not prompt for each field; it uses the
  8518.    default values.
  8519.  
  8520.  /c character_type
  8521.    Performs the copy operation with character type as the default. This
  8522.    option does not prompt for each field; it uses char as the default storage
  8523.    type, no prefixes, \t as the default field separator, and \n as the
  8524.    default row terminator.
  8525.  
  8526.  /t field_term
  8527.    Specifies the default field terminator.
  8528.  
  8529.  /r row_term
  8530.    Specifies the default row terminator.
  8531.  
  8532.  /i input_file
  8533.    Specifies the input file.
  8534.  
  8535.  /o output_file
  8536.    Specifies the output file.
  8537.  
  8538.  /U login_id
  8539.    Specifies a login ID.
  8540.  
  8541.  /P password
  8542.    Allows the user to specify a password. If the /P option is not used, bcp
  8543.    prompts for a password. If the /P option is used at the end of the command
  8544.    line without any password, bcp uses the default password (NULL).
  8545.  
  8546.  /I interface
  8547.    Allows the user to specify a pathname for the interface file. This is for
  8548.    compatibility with bcp in other environments only.
  8549.  
  8550.  /S servername
  8551.    Allows the user to specify the name of the SQL Server to connect to. This
  8552.    is the name that SQL Server looks up in the interfac file.
  8553.  
  8554.  /v version
  8555.    Reports the current version of the bcp program.
  8556.  
  8557.  ────────────────────────────────────────────────────────────────────────────
  8558.  When the transfer is complete, the program reports the number of rows
  8559.  successfully copied and some performance information. Here is a complete
  8560.  list of steps that may need to be performed to copy data into SQL Server at
  8561.  maximum speed:
  8562.  
  8563. ╓┌─────────────────────────────────────┌─────────────────────────────────────╖
  8564.  Steps                                 Notes / Who Can Do It
  8565.  ────────────────────────────────────────────────────────────────────────────
  8566.  1. Use sp_dboption to set select      SA.
  8567.  into/bulkcopy to true, and then
  8568.  execute CHECKPOINT in the database
  8569.  that was changed.
  8570.  Steps                                 Notes / Who Can Do It
  8571.  ────────────────────────────────────────────────────────────────────────────
  8572. that was changed.
  8573.  
  8574.  2. Drop the indexes on the table.     Table owner.
  8575.  
  8576.  3. Be sure that you have insert       Can be changed by table owner.
  8577.  permission on the table.
  8578.  
  8579.  4. Perform the copy with bcp.         Any user with insert permission.
  8580.  
  8581.  5. Use DUMP DATABASE to back up the   SA or Database Owner.
  8582.  newly inserted data.
  8583.  
  8584.  6. Re-create the indexes.             Check to be sure that you have
  8585.                                        enough space.
  8586.  
  8587.  7. Reset sp_dboption, if desired,     SA.
  8588.  and execute CHECKPOINT in the
  8589.  database that was changed.
  8590.  
  8591.  Steps                                 Notes / Who Can Do It
  8592.  ────────────────────────────────────────────────────────────────────────────
  8593. 
  8594.  8. Execute stored procedures or       Table owner or stored procedure
  8595.  queries to check if any of the newly  owner.
  8596.  loaded data violates rules.
  8597.  
  8598.  ────────────────────────────────────────────────────────────────────────────
  8599.  
  8600.  
  8601.  
  8602.  
  8603.  Native and Character Options
  8604.  
  8605.  The bcp program provides two command line options that create files with
  8606.  frequently used default formats. The /n option uses "native" (database)
  8607.  datatypes. The /c option uses "character" (char) for all columns, providing
  8608.  tabs between fields on a row and a newline at the end of each row. If you
  8609.  are using the /n or /c options, bcp operates noninteractively. It does not
  8610.  query you for any information on a column-by-column basis.
  8611.  
  8612.  
  8613.  Native Format
  8614.  
  8615.  The following command copies the publishers table to the file called
  8616.  publ_out, using native data format:
  8617.  
  8618.    bcp pubs..publishers out publ_out /n /S yourserver /U sa
  8619.  
  8620.  Here are the contents of publ_out:
  8621.  
  8622.    0736^MNew Age Books^FBoston^BMA0877^PBinnet & Hardley^J
  8623.     Washington^BDC1389^TAlgodata Infosystems^HBerkeley^BCA
  8624.  
  8625.  The bcp program has prefixed each field (except the pub_id, which is a
  8626.  char(4) datatype) with an ASCII character equivalent to the length of the
  8627.  data in the field. For example, "New Age Books" is 13 characters; and M
  8628.  (CTRL-M) is ASCII 13. All of the data in this table is char or varchar data,
  8629.  so we can read it. In a table with numeric data, the information would be
  8630.  written to the file in MS OS/2 system data format.
  8631.  
  8632.  
  8633.  Character Format
  8634.  
  8635.  Here is how you would copy the same file in character format:
  8636.  
  8637.    bcp pubs..publishers out publ_out /c /S yourserver /U sa
  8638.  
  8639.  This is the output:
  8640.  
  8641.    0736 New Age Books    Boston   MA
  8642.     0877 Binnet & Hardley   Washington  DC
  8643.     1389 Algodata Infosystems  Berkeley  CA
  8644.  
  8645.  
  8646.  Changing Terminators for Character Format
  8647.  
  8648.  The /t and /r options can be used with the /c option to change the
  8649.  terminators. The following example uses the comma as a field terminator and
  8650.  the return (\r) as the row terminator:
  8651.  
  8652.    bcp pubs..publishers out publ_out /c /t , /r \r /S yourserver
  8653.    /U sa
  8654.  
  8655.  This produces:
  8656.  
  8657.    0736,New Age Books,Boston,MA
  8658.     0877,Binnet & Hardley,Washington,DC
  8659.     1389,Algodata Infosystems,Berkeley,CA
  8660.  
  8661.  You can also use the /t and /r options to change the default terminators
  8662.  when the /c option is not used.
  8663.  
  8664.  ────────────────────────────────────────────────────────────────────────────
  8665.  NOTE
  8666.  
  8667.  The /n and /c options provide the easiest means of copying data to and from
  8668.  SQL Server. If these options meet your needs, you can skip to "Example of
  8669.  Copying a File to a Database Table," later in this chapter.
  8670.  ────────────────────────────────────────────────────────────────────────────
  8671.  
  8672.  
  8673.  Changing the Defaults: Interactive bcp
  8674.  
  8675.  If you do not use /n or /c, the program prompts you for further information,
  8676.  including the storage type, prefix length, and terminator for each column of
  8677.  data being copied. For fields that are to be stored as char or binary, bcp
  8678.  also prompts for a field length. (See the next section, "File Storage
  8679.  Type.")
  8680.  
  8681.  The default values at these prompts produce exactly the same results as
  8682.  using the /n option and provide a simple means for copying data out of a
  8683.  database for later reloading into SQL Server. If you are copying data to or
  8684.  from SQL Server for use with other programs, your answers to the prompts
  8685.  will depend on the format required by the other software.
  8686.  
  8687.  You may skip a table column on input or output by specifying 0 prefix
  8688.  length, 0 length, and no terminator.
  8689.  
  8690.  After information is gathered about each field in the table, the last
  8691.  prompts from bcp ask if you want to save a format file and then for the
  8692.  filename. This format file can be used to copy the data back into SQL Server
  8693.  or to copy data out from the table at another time. When you are copying
  8694.  data in or out using an existing format file, you are not prompted for
  8695.  information; the format file provides the information needed.
  8696.  
  8697.  The following table shows the defaults and possible responses for each of
  8698.  the four prompts:
  8699.  
  8700.  Prompt             Default Provided            Possible Responses
  8701.  ────────────────────────────────────────────────────────────────────────────
  8702.  File Storage Type  Database storage type for   char to create or read an
  8703.                     most fields; char for       ASCII file; any SQL Server
  8704.                     varchar; binary for         datatype where implicit
  8705.                     varbinary.                  conversion is supported.
  8706.  
  8707.  Prefix Length      0 for fields defined with   0 if no prefix is desired;
  8708.                     datatype  (not storage      defaults are recommended in
  8709.                     type) char and all          all other cases.
  8710.                     fixed-length datatypes, 1
  8711.                     for most other datatypes,
  8712.                     2 for binary, and
  8713.                     varbinary 4 for text and
  8714.                     image.
  8715.  
  8716.  Length             Defined length for char     Default values or greater
  8717.                     and varchar. Defined        are recommended.
  8718.                     length * 2 for binary and
  8719.                     varbinary saved as char.
  8720.                     Maximum length needed to
  8721.                     avoid truncation or data
  8722.                     overflow for all other
  8723.                     datatypes.
  8724.  
  8725.  Field Terminator   None.                       Up to 30 ASCII characters
  8726.                                                 or one of the following:
  8727.                                                 \t    tab
  8728.                                                 \n    newline
  8729.                                                 \r    carriage return
  8730.                                                 \0    null terminator
  8731.                                                 \\    backslash
  8732.  
  8733.  ────────────────────────────────────────────────────────────────────────────
  8734.  
  8735.  
  8736.  The responses to these four prompts provide an extremely flexible system
  8737.  that allows you to write a file that requires little or no editing to
  8738.  conform to many other data formats or to read files from other software. The
  8739.  following sections describe each of these prompts and the ways that they
  8740.  interact to affect the data. Remember that the default responses to these
  8741.  prompts are designed for the fastest and easiest method of copying data to
  8742.  and from SQL Server and that other acceptable responses provide ways to
  8743.  create other data formats.
  8744.  
  8745.  
  8746.  File Storage Type
  8747.  
  8748.  The file storage type describes the way the data is stored in the file. You
  8749.  can copy data into a file either as its database table type or as a
  8750.  character string in ASCII format, or as any datatype for which implicit
  8751.  conversion is supported for the datatype in question. User-defined datatypes
  8752.  are copied as their base types. The following table shows the storage types
  8753.  that can be used with bcp and the defaults for each SQL Server datatype. For
  8754.  the most compact storage, use the default value; for ASCII files, use char.
  8755.  
  8756.  
  8757. ╓┌────────────────────────────┌──────────────────────────────────────────────╖
  8758.  Storage Type                 Abbreviation
  8759.  Storage Type                 Abbreviation
  8760.  ────────────────────────────────────────────────────────────────────────────
  8761.  char                         c[har]
  8762.  varchar                      c[har]
  8763.  text                         T[ext]
  8764.  binary                       x
  8765.  varbinary                    x
  8766.  image                        I[mage]
  8767.  int                          i[nt] *
  8768.  smallint                     s[mallint] *
  8769.  tinyint                      t[inyint] *
  8770.  float                        f[loat] *
  8771.  bit                          b[it]
  8772.  money                        m[oney] *
  8773.  date                         d[ate] *
  8774.  ────────────────────────────────────────────────────────────────────────────
  8775.  
  8776.  
  8777.  * Length is dependent on the data. For example, an int of 23 has a storage
  8778.  length of 2 bytes plus the prefix and terminator (if any); an int of 5, 238,
  8779.  876 has a storage length of 7 bytes plus the prefix and terminator (if any).
  8780.  
  8781.  
  8782.  Giving a type other than char or a datatype that represents a legitimate
  8783.  implicit conversion causes bcp to fail. For example, you cannot use smallint
  8784.  for int data (you will get overflow errors), but you can use int for
  8785.  smallint.
  8786.  
  8787.  When numeric datatypes are stored as their database types, the data is
  8788.  written to the file in MS OS/2 data representation format, rather than in
  8789.  human-readable form.
  8790.  
  8791.  
  8792.  Prefix Length
  8793.  
  8794.  To provide the most compact file storage, bcp's default mode precedes each
  8795.  field, except those defined as char, with a string of one or more characters
  8796.  that indicate the length of the field. The default values in the prompts
  8797.  indicate the most efficient prefix lengths.
  8798.  
  8799.  For fields of 255 characters or less, the default prefix length is 1. For
  8800.  text or image datatypes, the default prefix length is 4. When binary and
  8801.  varbinary datatypes are being converted to char storage types, the default
  8802.  prefix length is 2, since 2 bytes of storage are required for each byte of
  8803.  table data.
  8804.  
  8805.  To store data with no prefix before the column, use a prefix length of 0.
  8806.  Each stored field is padded with spaces to the full length specified at the
  8807.  next "length" prompt.
  8808.  
  8809.  
  8810.  Length
  8811.  
  8812.  In almost all cases, you want to accept the bcp default value for the
  8813.  storage length. If you are making a file for later reloading into SQL
  8814.  Server, using a prefix with the default storage type and the default length
  8815.  keeps the storage space needed to a minimum. If you are creating an ASCII
  8816.  file, using the default length ensures that you won't truncate the data or
  8817.  create overflow errors that cause bcp to fail.
  8818.  
  8819.  You can change the default length by supplying another value.
  8820.  
  8821.  If the storage type is noncharacter, the data is stored in MS OS/2 native
  8822.  data representation. You are not asked to provide a length.
  8823.  
  8824.  When bcp converts noncharacter data to character storage, it suggests a
  8825.  default field length large enough to store the data without truncating
  8826.  datetime data or causing overflow of numeric data. These are the default
  8827.  field lengths:
  8828.  
  8829. ╓┌───────────────────────────┌───────────────────────────────────────────────╖
  8830.  Datatype                    Length
  8831.  ────────────────────────────────────────────────────────────────────────────
  8832.  int                         12 bytes
  8833.  smallint                    6 bytes
  8834.  tinyint                     3 bytes
  8835.  float                       25 bytes
  8836.  money                       24 bytes
  8837.  datetime                    20 bytes
  8838.  bit                         1 byte
  8839.  ────────────────────────────────────────────────────────────────────────────
  8840.  
  8841.  
  8842.  If you specify a field length that is too short for numeric data when you
  8843.  are copying data out, bcp prints an overflow message and does not copy the
  8844.  data. When datetime data is stored as a character string of less than 20
  8845.  bytes, the data is silently truncated.
  8846.  
  8847.  The default length for binary and varbinary fields is twice the length
  8848.  defined for the column since 2 bytes of storage are required for each byte
  8849.  of the field. If you accept the default, the actual amount of storage space
  8850.  allocated depends on whether or not you specify a prefix length and/or
  8851.  terminators:
  8852.  
  8853.  
  8854.    ■   If you do specify a prefix length of 1, 2, or 4, the storage space
  8855.        used is the actual length of the data plus the length of the prefix,
  8856.        plus any terminators.
  8857.  
  8858.    ■   If you specify a prefix length of 0 and no terminator, bcp allocates
  8859.        the maximum amount of space shown in the prompt, which is the maximum
  8860.        space that may be needed for the datatype in question. In other words,
  8861.        the field is treated as if it were fixed length so that it is possible
  8862.        to determine where one field ends and the next begins. For example, if
  8863.        the field is defined as varchar(30), bcp uses 30 characters for each
  8864.        value, even if some of the values are only one character long. The
  8865.        char datatypes are always padded to their full specified length.
  8866.  
  8867.  
  8868.  The following tables show the interaction of prefix lengths, terminators,
  8869.  and field length on the information in the file. "P" indicates the prefix in
  8870.  the stored table, "T" indicates the terminator, and dashes "--" indicate
  8871.  appended spaces. "..." indicates that the pattern repeats for each field.
  8872.  The field length is 8 for each column, and the 6-character field "string" is
  8873.  stored each time.
  8874.  
  8875.  Table 10.1  SQL Server char Data
  8876.  
  8877.                 Prefix Length = 0      Prefix Length 1, 2, or 4
  8878.  ────────────────────────────────────────────────────────────────────────────
  8879.  No terminator  string--string--...    Pstring--Pstring--...
  8880.  Terminator     string--Tstring--T...  Pstring--TPstring--T...
  8881.  ────────────────────────────────────────────────────────────────────────────
  8882.  
  8883.  Table 10.2  Other Datatypes Converted to char
  8884.  
  8885.                 Prefix Length = 0    Prefix Length 1, 2, or 4
  8886.  ────────────────────────────────────────────────────────────────────────────
  8887.  No terminator  string--string--...  PstringPstring...
  8888.  Terminator     stringTstringT...    PstringTPstringT...
  8889.  ────────────────────────────────────────────────────────────────────────────
  8890.  
  8891.  
  8892.  Field Terminator
  8893.  
  8894.  You can use an optional terminator to mark the end of a column, separating
  8895.  one from the next. The default is no terminator. To accept the default,
  8896.  press ENTER when prompted.
  8897.  
  8898.  When you are preparing data for use with other programs and when you want to
  8899.  use bcp to prepare tabular data, you will often want to supply your own
  8900.  terminators. The following terminators can be used:
  8901.  
  8902.  
  8903.    ■   Tabs, indicted by \t.
  8904.  
  8905.    ■   Newlines, indicated by \n.
  8906.  
  8907.    ■   Carriage returns, indicated by \r.
  8908.  
  8909.    ■   Backslash, indicated by \\.
  8910.  
  8911.    ■   Null terminators (no visible terminator), indicated by \0.
  8912.  
  8913.    ■   Any printable character (*, A, t, |, and so on).
  8914.  
  8915.    ■   Strings of up to 10 printable characters, including some or all of the
  8916.        terminators listed earlier (**\t**, end, !!!!!!!!!!, \t--\n, and so
  8917.        on). Control characters are not printable.
  8918.  
  8919.  
  8920.  Note that no terminator is different from the null terminator. The former
  8921.  puts no terminator after the column. The latter puts a true NULL after the
  8922.  column. A NULL character is an invisible but real character.
  8923.  
  8924.  The /t and /r options let you change the default terminators. When you use
  8925.  these options, the default that is listed on the prompt changes to the value
  8926.  you specify on the command line. The following example changes the default
  8927.  field terminator to the TAB character (\t) and the default row terminator to
  8928.  newline (\n):
  8929.  
  8930.    bcp pubs..publishers out publ_out /t \t /r \n /S yourserver
  8931.    /U sa
  8932.  
  8933.  
  8934.  Indexes
  8935.  
  8936.  For copying data in, the bcp program is fastest if your database table has
  8937.  no indexes. Fast bcp does not log data inserts in the transaction log.
  8938.  
  8939.  When you copy into a table that has indexes, a slower version of the bcp is
  8940.  automatically used. The slow version, which does log data inserts in the
  8941.  transaction log, can cause the transaction log to become very large. After
  8942.  backing up your database with DUMP DATABASE, you can truncate the
  8943.  transaction log with DUMP TRANSACTION WITH TRUNCATE_ONLY.
  8944.  
  8945.  ────────────────────────────────────────────────────────────────────────────
  8946.  NOTE
  8947.  
  8948.  For any user to copy in data using the fast version of bcp, the SA or
  8949.  Database Owner must first execute the sp_dboption system procedure, setting
  8950.  the select into/bulkcopy option. If the option is not set and a user tries
  8951.  to copy data into a table that does not have indexes, SQL Server generates
  8952.  an error message.
  8953.  ────────────────────────────────────────────────────────────────────────────
  8954.  
  8955.  You don't need to set the select into/bulkcopy option to copy data out or
  8956.  run bcp on a table that does have indexes because tables with indexes are
  8957.  always copied with the slower version and are logged.
  8958.  
  8959.  While the select into/bulkcopy option is set, you are not allowed to dump
  8960.  the transaction log because these operations are not logged and changes are
  8961.  therefore not recoverable from transaction logs. In this situation,
  8962.  executing the DUMP TRANSACTION statement produces an error message
  8963.  instructing you to use DUMP DATABASE instead.
  8964.  
  8965.  This table shows which version of bcp will be used when copying in, the
  8966.  necessary settings for the select into/bulkcopy option, and whether the
  8967.  transaction log is kept and can be dumped.
  8968.  
  8969.                        select into/bulk copy
  8970.                        ON                       OFF
  8971.  ────────────────────────────────────────────────────────────────────────────
  8972.  Fast bcp              OK                       prohibited
  8973.  (no indexes on        DUMP TRAN prohibited
  8974.  target table)
  8975.  
  8976.  Slow bcp              OK                       OK
  8977.  (one or more indexes)  DUMP TRAN prohibited     DUMP TRAN OK
  8978.  
  8979.  ────────────────────────────────────────────────────────────────────────────
  8980.  
  8981.  
  8982.  By default, the select into/bulkcopy option is off in newly created
  8983.  databases. To change the default, set this option in the model database.
  8984.  
  8985.  The performance penalty for copying data into a table that has indexes in
  8986.  place can be severe. If you are copying a very large number of rows, it may
  8987.  be faster to drop all the indexes beforehand with DROP INDEX, set the
  8988.  database option, copy the data into the table, dump the database, and then
  8989.  re-create the indexes. However, you need to allocate disk space for the
  8990.  construction of the indexes─about 2.2 times the amount of space needed for
  8991.  the data.
  8992.  
  8993.  
  8994.  Data Integrity: Defaults, Rules, and Triggers
  8995.  
  8996.  When data is copied into a table, any defaults defined for the columns and
  8997.  datatypes in the table are observed. That is, if there is a null field in
  8998.  the data in a file, the default value is loaded instead during the copy. For
  8999.  example, here are two rows in a file that are to be loaded into authors:
  9000.  
  9001.    409-56-7008,Bennet,Abraham,415 658-9932,6223 Bateman
  9002.    St.,Berkeley,CA,94705,1
  9003.    213-46-8915,Green,Marjorie,,309 63rd St. #411,Oakland,CA,94618,1
  9004.  
  9005.  Commas separate the fields; a newline separates the rows. Note that there is
  9006.  no phone number for Marjorie Green. If the phone column of the titles table
  9007.  had a default of "unknown," the rows in the loaded table would look like
  9008.  this:
  9009.  
  9010.    409-56-7008 Bennet Abraham  415 658-9932 6223 Bateman St.
  9011.     Berkeley CA  94705 1
  9012.    213-46-8915 Green Marjorie unknown   309 63rd St. #41
  9013.     Oakland  CA  94618 1
  9014.  
  9015.  However, rules and triggers are ignored to load data at the maximum speed.
  9016.  To find any rows that violate rules and triggers, copy the data into the
  9017.  table and run queries or stored procedures that test the rule or trigger
  9018.  conditions.
  9019.  
  9020.  
  9021.  Example of Copying a Database Table to a File
  9022.  
  9023.  In the following example, bcp copies data from the publishers table to a
  9024.  file for later reloading into SQL Server using a format file. It creates an
  9025.  output file, delimited with commas, with a newline at the end of each row
  9026.  and commas between all fields in a row.
  9027.  
  9028.    bcp pubs..publishers out publ_out /S yourserver /U sa
  9029.     Password:
  9030.  
  9031.     Enter the file storage type of field pub_id [char]:
  9032.     Enter prefix length of field pub_id [0]:
  9033.     Enter length of field pub_id [4]:
  9034.     Enter field terminator [none]:
  9035.  
  9036.     Enter the file storage type of field pub_name [char]:
  9037.     Enter prefix length of field pub_name [1]: 0
  9038.     Enter length of field pub_name [40]:
  9039.     Enter field terminator [none]:,
  9040.  
  9041.     Enter the file storage type of field city [char]:
  9042.     Enter prefix length of field city [1]: 0
  9043.     Enter length of field city [20]:
  9044.     Enter field terminator [none]:,
  9045.  
  9046.     Enter the file storage type of field state [char]:
  9047.     Enter prefix length of field state [1]: 0
  9048.     Enter length of field state [2]:
  9049.     Enter field terminator [none]: \n
  9050.  
  9051.     Do you want to save this format information in a file? [Y/n] y
  9052.     Host filename: [bcp_fmt] pub_fmt
  9053.  
  9054.      Starting copy...
  9055.  
  9056.     3 rows copied.
  9057.     Clock Time (ms.): total = 0      Avg = 0      (3.00 rows per sec.)
  9058.  
  9059.  These are the results in publ_out:
  9060.  
  9061.    0736,New Age Books,Boston,MA
  9062.     0877,Binnet & Hardley,Washington,DC
  9063.     1389,Algodata Infosystems,Berkeley,CA
  9064.  
  9065.  To copy this data back into SQL Server using the saved format file, type:
  9066.  
  9067.    bcp pubs..publishers in publ_out /f pub_fmt /S yourserver /U
  9068.    sa
  9069.  
  9070.  You could use the pub_fmt file to copy any data with the same format into
  9071.  SQL Server.
  9072.  
  9073.  
  9074.  Copying Data for Use with Other Programs
  9075.  
  9076.  By changing the default values of the prompts to bcp, you can prepare data
  9077.  for use with other software. In most cases, you'll want an ASCII file. The
  9078.  usual responses to the bcp prompts are as follows:
  9079.  
  9080.  
  9081.    ■   The storage type should be char.
  9082.  
  9083.    ■   The prefix length should be 0.
  9084.  
  9085.    ■   The field length should be the default.
  9086.  
  9087.    ■   The terminator depends on the software you plan to use. For output
  9088.        delimited with commas, use a comma as the terminator for each field.
  9089.        For tabular output, terminate the last field with the newline
  9090.        character, \n, and all other fields with the tab character, \t.
  9091.  
  9092.  
  9093.  The following example creates output in the personal computer format called
  9094.  SDF, or "system data format." Each field has a fixed length with spaces to
  9095.  pad the fields. Adjacent fields where the data completely fills the first
  9096.  field seem to run together since there are no field separators on each line
  9097.  of output. Only the final field has a terminator, \n, the newline character.
  9098.  This format can be easily read or produced by other software.
  9099.  
  9100.    bcp pubs..sales out sal_out /S yourserver /U sa
  9101.     Password:
  9102.  
  9103.     Enter the file storage type of field stor_id [char]:
  9104.     Enter prefix-length of field stor_id [1]: 0
  9105.     Enter length of field stor_id [4]:
  9106.     Enter field terminator [none]:
  9107.  
  9108.     Enter the file storage type of field ord_num [char]:
  9109.     Enter prefix-length of field ord_num [1]: 0
  9110.     Enter length of field ord_num [6]:
  9111.     Enter field terminator [none]:
  9112.  
  9113.     Enter the file storage type of field date [datetime]: char
  9114.     Enter prefix-length of field date [1]: 0
  9115.     Enter length of field date [6]:
  9116.     Enter field terminator [none]:
  9117.  
  9118.     Enter the file storage type of field qty [smallint]: char
  9119.     Enter prefix-length of field qty [1]: 0
  9120.     Enter length of field qty [6]:
  9121.     Enter field terminator [none]:
  9122.  
  9123.     Enter the file storage type of field payterms [char]:
  9124.     Enter prefix-length of field payterms [1]: 0
  9125.     Enter length of field payterms [12]:
  9126.     Enter field terminator [none]:
  9127.  
  9128.     Enter the file storage type of field title_id [char]:
  9129.     Enter prefix-length of field title_id [1]: 0
  9130.     Enter length of field title_id [6]:
  9131.     Enter field terminator [none]: \n
  9132.  
  9133.     Do you want to save this format information in a file? [Y/n]
  9134.     Host filename: [bcp_fmt] sal_fmt
  9135.  
  9136.     Starting copy...
  9137.  
  9138.     21 rows copied.
  9139.     Clock Time (ms.): total = 1000   Avg = 47     (21.00 rows per sec.)
  9140.     Change total and Avg to          Total = 1000  Avg = 47
  9141.  
  9142.  The following output is produced by bcp:
  9143.  
  9144.    7066QA7442.3 Sep 13 1985 12:00AM  75  On invoice   PS2091
  9145.     7067D4482  Sep 14 1985 12:00AM  10  Net 60    PS2091
  9146.     7131N914008  Sep 14 1985 12:00AM  20  Net 30    PS2091
  9147.     7131N914014  Sep 14 1985 12:00AM  25  Net 30    MC3021
  9148.     8042423LL922 Sep 14 1985 12:00AM  15  On invoice  MC3021
  9149.     8042423LL930 Sep 14 1985 12:00AM  10  On invoice  BU1032
  9150.     6380722a  Sep 13 1985 12:00AM  3  Net 60    PS2091
  9151.     63806871  Sep 14 1985 12:00AM  5  Net 60    BU1032
  9152.     8042P723  Mar 11 1988 12:00AM  25  Net 30    BU1111
  9153.     7896X999  Feb 21 1988 12:00AM  35  On invoice   BU2075
  9154.     7896QQ2299  Oct 28 1987 12:00AM  15  Net 60    BU7832
  9155.     7896TQ456  Dec 12 1987 12:00AM  10  Net 60    MC2222
  9156.     8042QA879.1  May 22 1987 12:00AM  30  Net 30    PC1035
  9157.     7066A2976  May 24 1987 12:00AM  50  Net 30    PC8888
  9158.     7131P3087a  May 29 1987 12:00AM  20  Net 60    PS1372
  9159.     7131P3087a  May 29 1987 12:00AM  25  Net 60    PS2106
  9160.     7131P3087a  May 29 1987 12:00AM  15  Net 60    PS3333
  9161.     7131P3087a  May 29 1987 12:00AM  25  Net 60    PS7777
  9162.     7067P2121  Jun 15 1987 12:00AM  40  Net 30   TC3218
  9163.     7067P2121  Jun 15 1987 12:00AM  20  Net 30    TC4203
  9164.     7067P2121  Jun 15 1987 12:00AM  20  Net 30    TC7777
  9165.  
  9166.  
  9167.  Example of Copying a File to a Database Table
  9168.  
  9169.  If you are copying data from a file into a table that has no indexes, make
  9170.  sure that the select into/bulkcopy option has been set. The SA or Database
  9171.  Owner can set this option by executing the sp_dboption system procedure.
  9172.  After you have completed the copy, back up the database with the DUMP
  9173.  DATABASE statement so that the copy and any subsequent changes can be
  9174.  recovered.
  9175.  
  9176.  In this example, bcp copies data from the file newpubs into the table
  9177.  pubs..publishers. First, here's what the newpubs file looks like:
  9178.  
  9179.    1111 Stone Age Books    Boston   MA
  9180.     2222 Harley & Davidson   Washington  DC
  9181.     3333 Infodata Algosystems  Berkeley  CA
  9182.  
  9183.  To copy data successfully into a table from a file, you must know what the
  9184.  terminators in the file are, and you must specify them when you use bcp. In
  9185.  the newpubs file, each field in a row is ended with a tab character (\t);
  9186.  each row ends with a newline (\n). Since the file is all character data, we
  9187.  can use the /c option and specify the terminators with /t for the field
  9188.  terminator and /r for the row terminator:
  9189.  
  9190.    bcp pubs..publishers in newpubs /c /t \t /r \n /S yourserver
  9191.    /U sa
  9192.     Password:
  9193.  
  9194.     Starting copy...
  9195.  
  9196.     3 rows copied.
  9197.     Clock Time (ms.): total = 0  Avg = 0  (3.00 rows per sec.)
  9198.  
  9199.  When you log in to SQL Server and access publishers, you see that the data
  9200.  from newpubs has been appended to the table:
  9201.  
  9202.    select * from publishers
  9203.  
  9204.     pub_id   pub_name    city   state
  9205.     ------   -------------------- ----------  -----
  9206.     0736  New Age Books   Boston   MA
  9207.     0877  Binnet & Hardley  Washington  DC
  9208.     1111  Stone Age Books   Boston   MA
  9209.     1389  Algodata Infosystems Berkeley  CA
  9210.     2222  Harley & Davidson  Washington  DC
  9211.     3333  Infodata Algosystems  Berkeley  CA
  9212.  
  9213.     (6 rows affected)
  9214.  
  9215.  Since there is a unique clustered index on the pub_id column of publishers,
  9216.  the new rows were sorted into order. Had there been any violations of the
  9217.  unique index on the pub_id column in the data being copied from the file,
  9218.  the violating row would have been discarded. If the types being copied in
  9219.  are incompatible with the database types, the entire copy fails.
  9220.  
  9221.  Note that the pub_id numbers of the three new publishers violate the rule on
  9222.  this column. An attempt to add these rows with the INSERT statement would
  9223.  have failed since they violate the rule. As explained earlier, bcp ignores
  9224.  rules so that data can be loaded at the highest possible speed.
  9225.  
  9226.  
  9227.  Error Files
  9228.  
  9229.  When the /e option is used when copying data from a file into a table, bcp
  9230.  stores all rows that it cannot copy into SQL Server in the specified error
  9231.  file. Error messages are sent to the user's workstation. The following
  9232.  example shows how the newpubs file would be loaded into the publishers
  9233.  database, with any error rows stored in the file pub_err:
  9234.  
  9235.    bcp pubs..publishers in newpubs /e pub_err /S yourserver /U
  9236.    sa
  9237.  
  9238.  
  9239.  
  9240.  
  9241.  
  9242.  
  9243.  Chapter 11  Diagnosing System Problems
  9244.  ────────────────────────────────────────────────────────────────────────────
  9245.  
  9246.  
  9247.  Introduction
  9248.  
  9249.  This chapter describes the following methods of diagnosing system problems:
  9250.  
  9251.  
  9252.  
  9253.    ■   Interpreting error messages
  9254.  
  9255.    ■   Stopping processes being carried out by SQL Server
  9256.  
  9257.    ■   Using the Database Consistency Checker (DBCC)
  9258.  
  9259.  
  9260.  
  9261.  Error Log
  9262.  
  9263.  Most error messages from SQL Server go to the user's screen.
  9264.  
  9265.  The backtrace from fatal error messages (severity levels 19 and higher) and
  9266.  error messages from the kernel are sent to a file named errorlog. See the
  9267.  SQL Server Language Reference.
  9268.  
  9269.  SQL Server creates errorlog if it does not already exist.
  9270.  
  9271.  Each time a particular server is started with net start sqlserver, a backup
  9272.  of the errorlog file is made in the \sql\log subdirectory. Seven log backups
  9273.  are kept. Information on the success (or failure) of the start is appended
  9274.  to the errorlog file. Subsequent fatal error messages and all kernel error
  9275.  messages are appended to errorlog.
  9276.  
  9277.  
  9278.  Error Messages
  9279.  
  9280.  When SQL Server encounters a problem─whether caused by the user or the
  9281.  system─it displays an error message. Error messages contain the following
  9282.  information:
  9283.  
  9284.  
  9285.    ■   A message number, which uniquely identifies the error message
  9286.  
  9287.    ■   A severity level between 10 and 25
  9288.  
  9289.    ■   An error state number, which allows unique identification of the line
  9290.        of SQL Server code at which the error occurred
  9291.  
  9292.    ■   A message, which tells you what the problem is and possibly how to fix
  9293.        it
  9294.  
  9295.  
  9296.  For example, if you try to access a table that doesn't exist, you would get
  9297.  the following message:
  9298.  
  9299.    select * from pulbihsers
  9300.  
  9301.     Msg 208, Level 16, State 1:
  9302.     Invalid object(table) name  pulbihsers
  9303.  
  9304.  A single error condition can have more than one error message. For example,
  9305.  SQL Server responds to a syntax error as follows:
  9306.  
  9307.    slect * from publishers
  9308.  
  9309.     Msg 101, Level 15, State 1:
  9310.     Line 1: SQL syntax error.
  9311.     Msg 102, Level 15, State 1:
  9312.     Incorrect syntax near '*'.
  9313.  
  9314.  If there is more than one error in a statement, SQL Server displays
  9315.  information about the first one.
  9316.  
  9317.  The error messages are stored in master..sysmessages. The first few rows
  9318.  look like this:
  9319.  
  9320.    error            severity           dlevel
  9321.                description
  9322.    ------------------------------------------------------------
  9323.            101              15                 2
  9324.                Line %d: SQL syntax error.
  9325.            102              15                 2
  9326.                Incorrect syntax near '%.*s'.
  9327.            103              15                 2
  9328.                The %s/ '%.*s' is too long. Maximum length is %d.
  9329.            105              15                 2
  9330.                Unclosed quote before the character string '%.*s'.
  9331.            106              16                 2
  9332.                Too many table names in the query. The maximum allowable is
  9333.  %d.
  9334.  
  9335.            (5 rows affected)
  9336.  
  9337.  You can generate the list of error messages by querying sysmessages.
  9338.  
  9339.  
  9340.  Message Numbers
  9341.  
  9342.  The message number uniquely identifies the text of each error message.
  9343.  
  9344.  The error message text is a description of the problem. The descriptions
  9345.  often include a line number and a reference to a kind of database object (a
  9346.  table, column, stored procedure, and so on), or the name of a particular
  9347.  database object.
  9348.  
  9349.  In the description field of sysmessages, a percent symbol (%) followed by a
  9350.  character serves as a placeholder for these pieces of data, which SQL Server
  9351.  supplies when it encounters the problem and generates the error message.
  9352.  "%d" is a placeholder for a number; "%s" is a placeholder for a kind of
  9353.  database object; "%.*s" (within single quotation marks) is a placeholder for
  9354.  the name of a particular database object.
  9355.  
  9356.  For example, the description field for message number 103 is
  9357.  
  9358.    The %s that starts with '%.*s' is too long. Maximum length
  9359.    is %d.
  9360.  
  9361.  The actual error message displayed to a user might be
  9362.  
  9363.    The column that starts with 'title' is too long. Maximum length
  9364.    is 80.
  9365.  
  9366.  For errors that you report, it is important to include the numbers, object
  9367.  types, and object names. (See "Reporting Errors," later in this chapter, for
  9368.  more information.)
  9369.  
  9370.  
  9371.  Severity Levels
  9372.  
  9373.  The severity level provides a clue about the kind of problem SQL Server has
  9374.  encountered.
  9375.  
  9376.  Severity levels begin with level 10. Levels 10 through 16 indicate problems
  9377.  caused by mistakes in what users have entered.
  9378.  
  9379.  Severity levels 17 or higher indicate software or hardware errors. If the
  9380.  number is 17 or 18, you can continue the work you're doing (though you may
  9381.  not be able to execute a particular statement).
  9382.  
  9383.  Severity levels 19 or higher are system problems. They are fatal errors,
  9384.  which means that the process (the program code that is running to accomplish
  9385.  the task that you specified in your statement) is no longer running. The
  9386.  process freezes its state before it stops, recording information about what
  9387.  was happening. It is then stopped and disappears.
  9388.  
  9389.  These errors break the user's connection to SQL Server. Depending on the
  9390.  problem, a user may or may not be able to reconnect and resume working. Some
  9391.  problems with severity levels in this range affect only one user and one
  9392.  process. Others affect all the processes in the database. These problems
  9393.  don't necessarily damage a database or its objects, but they can. Still
  9394.  other problems are caused by hardware malfunctions.
  9395.  
  9396.  A backtrace of error messages from the kernel is directed to the error log
  9397.  file, where the SA can review it. See "Error Messages," earlier in this
  9398.  chapter, for information on the errorlog file.
  9399.  
  9400.  Users should be instructed to inform the SA whenever problems that generate
  9401.  severity levels 17 or higher occur. The SA is responsible for resolving them
  9402.  and tracking their frequency. The SA should monitor all problems that
  9403.  generate severity levels 18 through 24 and print out a hard copy of the
  9404.  error log, which contains the backtrace from the fatal error.
  9405.  
  9406.  If the problem affects an entire database, the SA may have to use the
  9407.  Database Consistency Checker (DBCC) to determine the extent of the damage.
  9408.  The DBCC may identify some objects that must be removed. It can repair some
  9409.  damage, but the database may also have to be reloaded. See "Database
  9410.  Consistency Checker," later in this chapter, for more information on the
  9411.  DBCC. Loading a database is discussed in Chapter 8, "Backup and Recovery."
  9412.  
  9413.  The following list discusses each severity level.
  9414.  
  9415.  ────────────────────────────────────────────────────────────────────────────
  9416.  Severity Levels 10 through 18
  9417.    Error messages with severity level 10 are informative only. Error messages
  9418.    with severity levels 11 through 16 are generated by user errors and can be
  9419.    corrected by the user. Severity levels 17 and 18 don't indicate infected
  9420.    processes, so the user's session is not interrupted.
  9421.  
  9422.    Error messages with severity levels 17 or higher should be reported to the
  9423.    SA or Database Owner.
  9424.  
  9425.  Severity Level 10: Status Information
  9426.    Messages with severity level 10 are not errors; they provide additional
  9427.    information after certain statements have been executed. For example,
  9428.    after a CREATE DATABASE statement has executed, SQL Server displays a
  9429.    message telling the user how much space has actually been allocated for
  9430.    the new database.
  9431.  
  9432.  Severity Level 11: Specified Database Object Not Found
  9433.    Messages with severity level 11 indicate that SQL Server can't find an
  9434.    object referenced in the statement. This is often because you have made a
  9435.    mistake in typing the name of a database object or you are confused about
  9436.    which database is current.
  9437.  
  9438.    Check spelling of object names and make sure you're in the correct
  9439.    database.
  9440.  
  9441.  Severity Level 12: Wrong Datatype Encountered
  9442.    Messages with severity level 12 indicate a problem with datatypes. For
  9443.    example, you may have tried to enter a value of the wrong datatype into a
  9444.    field or compare fields of different (and incompatible) datatypes.
  9445.  
  9446.    To correct comparison problems, use the CONVERT function with SELECT. For
  9447.    information on CONVERT, see the SQL Server Language Reference or SQL
  9448.    Server Learning TRANSACT-SQL.
  9449.  
  9450.  Severity Level 13: User Transaction Syntax Error
  9451.    Messages with severity level 13 indicate that something is wrong with the
  9452.    current user-defined transaction. For example, you may have executed a
  9453.    COMMIT TRANSACTION statement without having executed a BEGIN TRANSACTION,
  9454.    or you may have tried to roll a transaction back to a savepoint that has
  9455.    not been defined (sometimes there may be a typing or spelling mistake in
  9456.    the name of the savepoint).
  9457.  
  9458.    Severity level 13 can also indicate a deadlock, in which case your process
  9459.    is stopped. You must restart your statement.
  9460.  
  9461.  Severity Level 14: Insufficient Permission to Execute Command
  9462.    Messages with severity level 14 indicate that the user doesn't have the
  9463.    permission necessary to execute the statement or access the database
  9464.    object.
  9465.  
  9466.    The owner of the database object, the owner of the database, or the SA can
  9467.    grant the user permission to use the statement or object in question.
  9468.  
  9469.  Severity Level 15: Syntax Error in SQL Statements
  9470.    Messages with severity level 15 indicate that you have made a mistake in
  9471.    the syntax of the statement. The text of these error messages include the
  9472.    line number(s) on which the mistake occurred and the specific word near
  9473.    which it occurred.
  9474.  
  9475.  Severity Level 16: Miscellaneous User Error
  9476.    Error messages with severity level 16 indicate that you have made some
  9477.    kind of nonfatal mistake that doesn't fall into any of the above
  9478.    categories.
  9479.  
  9480.    For example, you may have tried to update a view in a way that violates
  9481.    the restrictions. Another error that falls into this category is
  9482.    unqualified column names:  including in a statement the unqualified name
  9483.    of a column when that name is used in more than one table. SQL Server has
  9484.    no way to determine which one you intend. Check statement syntax and
  9485.    current database context.
  9486.  
  9487.  Severity Level 17: Insufficient Resources
  9488.    Error messages with severity level 17 indicate that the statement has
  9489.    caused SQL Server to run out of resources (usually space for the database
  9490.    on the disk) or to exceed some limit set by the SA.
  9491.  
  9492.    These system limits include the number of databases that can be open at
  9493.    the same time and the number of connections allowed to SQL Server. They
  9494.    are stored in master..sysconfigures and can be changed with the
  9495.    RECONFIGURE statement. (See Chapter 9, "Fine-tuning Performance and
  9496.    Operations," for more information on RECONFIGURE.)
  9497.  
  9498.    Level 17 error messages that indicate you have run out of space will
  9499.    probably be corrected by the Database Owner. Other level 17 error messages
  9500.    are probably better addressed by the SA.
  9501.  
  9502.  Severity Level 18: Nonfatal Internal Error Detected
  9503.    Error messages with severity level 18 indicate some kind of internal
  9504.    software bug. However, the statement executes to completion, and the
  9505.    connection to SQL Server is maintained.
  9506.  
  9507.    Since problems that generate such messages don't keep users from their
  9508.    work, users may have a tendency not to report them. Users should be
  9509.    instructed to inform the SA every time an error message with this severity
  9510.    level (and higher levels) occurs so that the SA can report them.
  9511.  
  9512.    An example of a situation that generates severity level 18 is SQL Server
  9513.    detecting that a decision about the access path for a particular query has
  9514.    been made without a valid reason.
  9515.  
  9516.  Severity Levels 19 through 24
  9517.    Problems that generate error messages with severity levels 19 and higher
  9518.    are fatal. They can sometimes leave ongoing infected processes and break
  9519.    your connection to SQL Server. To continue working, restart the
  9520.    application program.
  9521.  
  9522.  Severity Level 19: SQL Server Fatal Error in Resource
  9523.    Error messages with severity level 19 indicate that some nonconfigurable
  9524.    internal limit has been exceeded and that SQL Server cannot recover
  9525.    gracefully. You must reconnect to SQL Server. See your SA.
  9526.  
  9527.  Severity Level 20: SQL Server Fatal Error in Current Process
  9528.    Error messages with severity level 20 indicate that SQL Server has
  9529.    encountered a bug in some statement. The problem has affected only the
  9530.    current process; it is unlikely that the database itself has been damaged.
  9531.    Run the DBCC diagnostics. You must reconnect to SQL Server. See your SA.
  9532.  
  9533.  Severity Level 21: SQL Server Fatal Error in Database (dbid) Processes
  9534.    Error messages with severity level 21 indicate that SQL Server has
  9535.    encountered a bug that affects all the processes in the current database.
  9536.    However, it is unlikely that the database itself has been damaged. Run the
  9537.    DBCC diagnostics. You must reconnect to SQL Server. See your SA.
  9538.  
  9539.  Severity Level 22: SQL Server Fatal Error Table Integrity Suspect
  9540.    Error messages with severity level 22 indicate that the table or index
  9541.    specified in the message has been damaged at some previous time by a
  9542.    software or hardware problem.
  9543.  
  9544.    The first step is to run DBCC to determine if other objects in the
  9545.    database are also damaged. Whatever the report from DBCC, it's possible
  9546.    that the problem is in the cache only and not on the disk itself. If so,
  9547.    restarting SQL Server will fix the problem.
  9548.  
  9549.    If restarting doesn't help, the problem is on the disk as well. Sometimes
  9550.    it can be solved by destroying the object specified in the error message.
  9551.    For example, if the message tells you that SQL Server has found a row with
  9552.    length 0 in a nonclustered index, there's no reason not to delete the
  9553.    index and rebuild it. Of course, there are a lot of objects you won't want
  9554.    to destroy.
  9555.  
  9556.    You must reconnect to SQL Server. See your SA.
  9557.  
  9558.  Severity Level 23: SQL Server Fatal Error: Database Integrity Suspect
  9559.    Error messages with severity level 23 indicate that the integrity of the
  9560.    entire database is suspect. The damage has been caused at some previous
  9561.    time by a software or hardware problem. Run DBCC to determine the extent
  9562.    of the damage.
  9563.  
  9564.    Even when the whole database is suspect, it's possible that the damage is
  9565.    confined to the cache and that the disk itself is fine. If so, restarting
  9566.    SQL Server fixes the problem.
  9567.  
  9568.  Severity Level 24: Hardware Error
  9569.    Error messages with severity level 24 indicate some kind of media failure.
  9570.    The SA may have to reload the database. It may be necessary to call the
  9571.    hardware vendor.
  9572.  
  9573.  ────────────────────────────────────────────────────────────────────────────
  9574.  Reporting Errors
  9575.  
  9576.  When you report an error, be sure to include the following information:
  9577.  
  9578.  
  9579.    ■   The message number, severity level, and error state number.
  9580.  
  9581.    ■   Any numbers, database object types, or database object names that are
  9582.        included in the error message.
  9583.  
  9584.    ■   The context in which the message was generated─which statement was
  9585.        running at the time. You can help by providing a hard copy of the
  9586.        backtrace from the error log. See "Error Log," earlier in this
  9587.        chapter, for information on the error log.
  9588.  
  9589.  
  9590.  
  9591.  Stopping Processes
  9592.  
  9593.  A process is a task being carried out by SQL Server. Processes can be
  9594.  initiated by a user giving a statement or by SQL Server itself. Each process
  9595.  is assigned a unique process identification number when it starts up. These
  9596.  ID numbers and other information about each process are stored in
  9597.  master..sysprocesses.
  9598.  
  9599.  The KILL statement is used to get rid of an ongoing process. Only the SA can
  9600.  execute the KILL statement; permission to use it cannot be transferred. The
  9601.  most frequent reason for stopping a process is that it interferes with other
  9602.  users and the person responsible for running it isn't available.
  9603.  
  9604.  To keep the system operating smoothly, the SA may want to check ongoing
  9605.  processes regularly by using the sp_who stored procedure. Another system
  9606.  procedure, sp_lock, also reports on processes. It gives information about
  9607.  all the locks currently held on SQL Server, including the spid of the
  9608.  process holding each one. The sp_lock system procedure is discussed in
  9609.  Chapter 9, "Fine-tuning Performance and Operations."
  9610.  
  9611.  You cannot stop processes called NETWORK HANDLER or CHECKPOINT. Other
  9612.  processes are stopped with the KILL statement. The KILL statement has the
  9613.  following syntax:
  9614.  
  9615.    KILL spid
  9616.  
  9617.  You can stop only one process at a time. A KILL statement is not reversible
  9618.  and cannot be put inside a user-defined transaction.
  9619.  
  9620.  ────────────────────────────────────────────────────────────────────────────
  9621.  NOTE
  9622.  
  9623.  Server processes cannot be killed. If you try to kill a server process, it
  9624.  will not be killed and will still be listed when you execute the sp_who
  9625.  system procedure.
  9626.  ────────────────────────────────────────────────────────────────────────────
  9627.  
  9628.  
  9629.  Database Consistency Checker
  9630.  
  9631.  The Database Consistency Checker (DBCC) program is a set of utility
  9632.  statements that checks the logical and physical consistency of a database.
  9633.  It is used for the following reasons:
  9634.  
  9635.  
  9636.    ■   A system error with a severity level of 20 to 23 has been generated.
  9637.  
  9638.    ■   The SA wants to make a periodic check.
  9639.  
  9640.    ■   You suspect that a database is damaged. (For example, if using a
  9641.        particular table generates the message corrupted data, you can use
  9642.        DBCC to determine if other tables in the database are also damaged.)
  9643.  
  9644.  
  9645.  The Database Owner is automatically granted permission to use the DBCC
  9646.  statement and its options. Permission for DBCC CHECKTABLE defaults to the
  9647.  table owner. Permission to run DBCC is not transferable.
  9648.  
  9649.  The DBCC program has the following syntax:
  9650.  
  9651.    DBCC {CHECKTABLE (table_name) |
  9652.     CHECKDB [(database_name)] |
  9653.     CHECKALLOC [(database_name)] |
  9654.     CHECKCATALOG [(database_name]) |
  9655.     DBREPAIR (database_name, DROPDB) }
  9656.  
  9657.  DBCC can be run while the database is active if the DBREPAIR option is not
  9658.  used.
  9659.  
  9660.  Because of the special status of sysindexes as a system catalog, it is
  9661.  necessary to qualify the update and restrict it to a single row in the
  9662.  manner described earlier. The value for the qualification's comparison to
  9663.  indid is 1 if there is a clustered index on that table and 0 if there is
  9664.  none.
  9665.  
  9666.  The following sections describe each option.
  9667.  
  9668.  
  9669.  The CHECKTABLE Option
  9670.  
  9671.  The CHECKTABLE option checks the specified table to see that index and data
  9672.  pages are correctly linked, that indexes are in properly sorted order, that
  9673.  all pointers are consistent, and that the data on each page and page offsets
  9674.  is reasonable.
  9675.  
  9676.  Here's an example:
  9677.  
  9678.    dbcc checktable (titles)
  9679.  
  9680.     Checking titles
  9681.     Message number is 2536.
  9682.     The total number of data pages in this table is 3.
  9683.     Message number is 2579.
  9684.     DBCC execution completed. If DBCC printed error
  9685.     messages, see your System Administrator.
  9686.     Message number is 2528.
  9687.  
  9688.  A warning message may be issued by DBCC, either during CHECKTABLE or
  9689.  CHECKDB, stating that the value in the dpages column of the sysindexes row
  9690.  is not the same as DBCC's count of data pages for some table. To correct
  9691.  this inconsistency:
  9692.  
  9693.  
  9694.    1.  Use the sp_configure stored procedure to enable updates to system
  9695.        catalogs.
  9696.  
  9697.    2.  Execute the SQL statement RECONFIGURE WITH OVERRIDE for that change in
  9698.        configuration to take effect.
  9699.  
  9700.    3.  When using the database where the DBCC check was done, execute this
  9701.        SQL statement:
  9702.  
  9703.        update sysindexes set dpages=<count from DBCC>
  9704.                where id=<id of table> and indid=<0 or 1>
  9705.  
  9706.  
  9707.    4.  Execute the CHECKPOINT statement in the database where the DBCC check
  9708.        was done.
  9709.  
  9710.    5.  Use sp_configure to disable updates to system catalogs.
  9711.  
  9712.    6.  Execute the RECONFIGURE statement.
  9713.  
  9714.  
  9715.  
  9716.  The CHECKDB Option
  9717.  
  9718.  The CHECKDB option runs the same checks as CHECKTABLE, but on each table in
  9719.  the specified database. If no database name is given, CHECKDB checks the
  9720.  current database. CHECKDB gives the same type of message as CHECKTABLE.
  9721.  
  9722.  
  9723.  The CHECKALLOC Option
  9724.  
  9725.  The CHECKALLOC option checks the specified database to see that all pages
  9726.  are correctly allocated and that no page is allocated that isn't used. If no
  9727.  database name is given, CHECKALLOC checks the current database.
  9728.  
  9729.  CHECKALLOC reports on the amount of space allocated and used. For example,
  9730.  here's a CHECKALLOC report on pubs:
  9731.  
  9732.    Checking pubs
  9733.     Message number is 2536.
  9734.     Database 'pubs' is not in single user mode - may find spurious allocation
  9735.     problems due to transactions in progress.
  9736.     Message number is 2572.
  9737.     Alloc page 0 (# of extent=3145759 used pages=117375024 ref pages=1)
  9738.     Message number is 2538.
  9739.     Alloc page 256 (# of extent=1376272 used pages=117374997 ref pages=1)
  9740.            Message number is 2538.
  9741.     Alloc page 512 (# of extent=65537 used pages=117374977 ref pages=1)
  9742.     Message number is 2538.
  9743.     Alloc page 768 (# of extent=65537 used pages=117374977 ref pages=1)
  9744.     Message number is 2538.
  9745.     Total (# of extent=46531052 used pages=117375047 ref pages=1) in
  9746.    this
  9747.     database
  9748.     Message number is 2539.
  9749.     DBCC execution completed. If DBCC printed error messages, see your
  9750.    System
  9751.     Administrator.
  9752.      Message number is 2528.
  9753.  
  9754.  This database contains four allocation units of one-half megabyte each, or 2
  9755.  megabytes in all (the default size of a database). There can be as many as
  9756.  32 extents (required for the creation of new database objects) per
  9757.  allocation unit; the number of extents tells you whether or not you can
  9758.  create new objects in this database. There are 8 pages per extent; the
  9759.  number of used pages tells you whether you can add data to existing objects.
  9760.  
  9761.  
  9762.  To get an approximation of the space used, multiply the total number of used
  9763.  pages by 2K.
  9764.  
  9765.  
  9766.  The CHECKCATALOG Option
  9767.  
  9768.  The CHECKCATALOG option checks for consistency within and between system
  9769.  tables. For example, it makes sure that every type in syscolumns has a
  9770.  matching entry in systypes, that every table and view in sysobjects has at
  9771.  least one column in syscolumns, and that the last checkpoint in syslogs is
  9772.  valid. If no database name is given, CHECKCATALOG checks the current
  9773.  database.
  9774.  
  9775.  Here's an example:
  9776.  
  9777.    dbcc checkcatalog (pubs)
  9778.  
  9779.        Checking pubs
  9780.        The following segments have been defined for database 4
  9781.        (database name pubs).
  9782.  
  9783.        virtual start addr    size      segments
  9784.        ------------------    -----     --------
  9785.        3076                  1024      0
  9786.                                        1
  9787.        5124                  1024      0
  9788.                                        1
  9789.        DBCC execution completed. If DBCC printed error messages, see your SA.
  9790.  
  9791.  
  9792.  The DBREPAIR Option
  9793.  
  9794.  The DBREPAIR option drops a damaged database. DROP DATABASE does not work on
  9795.  a damaged database.
  9796.  
  9797.  No users can be using the database being dropped or repaired when the
  9798.  DBREPAIR statement is executed (including the one who executed the
  9799.  statement). Execute the DBREPAIR statement from master.
  9800.  
  9801.  
  9802.  
  9803.  
  9804.  
  9805.  
  9806.  Appendix A  The pubs Sample Database
  9807.  ────────────────────────────────────────────────────────────────────────────
  9808.  
  9809.  This appendix describes the sample database, pubs. The pubs database has
  9810.  eight tables:
  9811.  
  9812.  
  9813.    ■   publishers
  9814.  
  9815.    ■   titleauthor
  9816.  
  9817.    ■   sales
  9818.  
  9819.    ■   stores
  9820.  
  9821.    ■   discounts
  9822.  
  9823.    ■   roysched
  9824.  
  9825.    ■   authors
  9826.  
  9827.    ■   titles
  9828.  
  9829.  
  9830.  Each database table is described by two figures. The first figure documents
  9831.  the structure of the table; for each table field, the figure lists its
  9832.  datatype, its NULL/NOT NULL status, and any defaults, rules, triggers, and
  9833.  indexes. The second figure lists the table contents.
  9834.  
  9835.  Table   publishers ─ Structure
  9836.  
  9837.            pub_id         pub_name     city         state
  9838.  ────────────────────────────────────────────────────────────────────────────
  9839.  Datatype  char(4)        varchar(40)  varchar(20)  char(2)
  9840.  Null      not null       null         null         null
  9841.  Rule      pub_idrule(1)  ─            ─            ─
  9842.  Index     clust, uniq    ─            ─            ─
  9843.  ────────────────────────────────────────────────────────────────────────────
  9844.  
  9845.  (1) The pub_idrule states that the data must be 1389, 0736, 0877, 1622, or
  9846.  1756, or must match the pattern  99[0-9][0-9].
  9847.  
  9848.  
  9849.  pub_id                            pub_name    city           state
  9850.  ────────────────────────────────────────────────────────────────────────────
  9851.  1389                              Algodata    Berkeley       CA
  9852.                                    Infosystem
  9853.                                    s
  9854.  
  9855.  0736                              New Age     Boston         MA
  9856.                                    Books
  9857.  
  9858.  0877                              Binnet &    Washington     DC
  9859.                                    Hardley
  9860.  
  9861.  Table   titleauthor ─ Structure
  9862.  
  9863.            au_id            title_id  au_ord    royaltyper
  9864.  ────────────────────────────────────────────────────────────────────────────
  9865.  Datatype  id               tid       smallint  int
  9866.  
  9867.  Null      not null         not null  null      null
  9868.  
  9869.  Index     nonclust         nonclust  ─         ─
  9870.  
  9871.            uniq, nonclust,
  9872.            composite
  9873.  
  9874.  ────────────────────────────────────────────────────────────────────────────
  9875.  
  9876.  
  9877.  Table   titleauthor ─ Contents
  9878.  
  9879. ╓┌────────────┌─────────┌───────┌────────────────────────────────────────────╖
  9880.  au_id        title_id  au_ord  royaltyper
  9881.  ────────────────────────────────────────────────────────────────────────────
  9882.  409-56-7008  BU1032    1       60
  9883.  213-46-8915  BU1032    2       40
  9884.  238-95-7766  PC1035    1       100
  9885.  213-46-8915  BU2075    1       100
  9886.  998-72-3567  PS2091    1       50
  9887.  899-46-2035  PS2091    2       50
  9888.  998-72-3567  PS2106    1       100
  9889.  722-51-5454  MC3021    1       75
  9890.  899-46-2035  MC3021    2       25
  9891.  807-91-6654  TC3218    1       100
  9892.  486-29-1786  PS7777    1       100
  9893.  au_id        title_id  au_ord  royaltyper
  9894.  ────────────────────────────────────────────────────────────────────────────
  9895. 486-29-1786  PS7777    1       100
  9896.  486-29-1786  PC9999    1       100
  9897.  712-45-1867  MC2222    1       100
  9898.  172-32-1176  PS3333    1       100
  9899.  274-80-9391  BU7832    1       100
  9900.  427-17-2319  PC8888    1       50
  9901.  846-92-7186  PC8888    2       50
  9902.  756-30-7391  PS1372    1       75
  9903.  724-80-9391  PS1372    2       25
  9904.  724-80-9391  BU1111    1       60
  9905.  267-41-2394  BU1111    2       40
  9906.  672-71-3249  TC7777    1       40
  9907.  267-41-2394  TC7777    2       30
  9908.  472-27-2349  TC7777    3       30
  9909.  648-92-1872  TC4203    1       100
  9910.  ────────────────────────────────────────────────────────────────────────────
  9911.  
  9912.  
  9913.  Table   sales ─ Structure
  9914.  
  9915.            stor_id   ord_num      date      qty       payterms     title_id
  9916.  ────────────────────────────────────────────────────────────────────────────
  9917.  Datatype  char(4)   varchar(20)  datetime  smallint  varchar(12)  tid
  9918.  Null      not null  not null     not null  not null  not null     not null
  9919.  Index     ─         ─            ─         ─         ─            nonclust
  9920.  ────────────────────────────────────────────────────────────────────────────
  9921.  
  9922.  Table   sales ─ Contents
  9923.  
  9924. ╓┌────────┌─────────┌─────────┌────┌───────────┌─────────────────────────────╖
  9925.  stor_id  ord_num   date      qty  payterms    title_id
  9926.  ────────────────────────────────────────────────────────────────────────────
  9927.  7066     QA7442.3  09/13/85  75   On invoice  PS2091
  9928.  7067     D4482     09/14/85  10   Net 60      PS2091
  9929.  7131     N914008   09/14/85  20   Net 30      PS2091
  9930.  7131     N914014   09/14/85  25   Net 30      MC3021
  9931.  8042     423LL922  09/14/85  15   On invoice  MC3021
  9932.  8042     423LL930  09/14/85  10   On invoice  BU1032
  9933.  6380     722a      09/13/85  03   Net 60      PS2091
  9934.  6380     6871      09/14/85  05   Net 60      BU1032
  9935.  stor_id  ord_num   date      qty  payterms    title_id
  9936.  ────────────────────────────────────────────────────────────────────────────
  9937. 6380     6871      09/14/85  05   Net 60      BU1032
  9938.  8042     P723      03/11/88  25   Net 30      BU1111
  9939.  7896     X999      02/21/88  35   On invoice  BU2075
  9940.  7896     QQ2299    10/28/87  15   Net 60      BU7832
  9941.  7896     TQ456     12/12/87  10   Net 60      MC2222
  9942.  8042     QA879.1   05/22/87  30   Net 30      PC1035
  9943.  7066     A2976     05/24/87  50   Net 30      PC8888
  9944.  7131     P3087a    05/29/87  20   Net 60      PS1372
  9945.  7131     P3087a    05/29/87  25   Net 60      PS2106
  9946.  7131     P3087a    05/29/87  15   Net 60      PS3333
  9947.  7131     P3087a    05/29/87  25   Net 60      PS7777
  9948.  7067     P2121     05/15/87  40   Net 30      TC3218
  9949.  7067     P2121     05/15/87  20   Net 30      TC4203
  9950.  7067     P2121     05/15/87  20   Net 30      TC7777
  9951.  ────────────────────────────────────────────────────────────────────────────
  9952.  
  9953.  
  9954.  Table   stores ─ Structure
  9955.  
  9956.             stor_id    stor_name    stor_addres  city         state    zip
  9957.                                     s
  9958.  ─────────────────────────────────────────────────────────────────────────────
  9959.  Datatype   char(4)    varchar(40)  varchar(40)  varchar(20)  char(2)  char(5)
  9960.  
  9961.  Null       not null   null         null         null         null     null
  9962.  
  9963.  ─────────────────────────────────────────────────────────────────────────────
  9964.  
  9965.  
  9966.  Table   stores ─ Contents
  9967.  
  9968. ╓┌────────┌────────────────────┌────────────────────┌──────────┌──────┌──────╖
  9969.  stor_id  stor_name            stor_address         city       state  zip
  9970.  ────────────────────────────────────────────────────────────────────────────
  9971.  7066     Barnum's             567 Pasadena Ave.    Tustin     CA     92789
  9972.  
  9973.  7067     News & Brews         577 First St.        Los Gatos  CA     96745
  9974.  
  9975.  7131     Doc-U-Mat: Quality   24-A Avrogado Way    Remulade   WA     98014
  9976.           Laundry and Books
  9977.  stor_id  stor_name            stor_address         city       state  zip
  9978.  ────────────────────────────────────────────────────────────────────────────
  9979.          Laundry and Books
  9980.  
  9981.  8042     Bookbeat             679 Carson St.       Portland   OR     89076
  9982.  
  9983.  6380     Eric the Read Books  788 Catamaugus Ave.  Seattle    WA     98056
  9984.  
  9985.  7896     Fricative Bookshop   89 Madison St.       Fremont    CA     90019
  9986.  
  9987.  ────────────────────────────────────────────────────────────────────────────
  9988.  
  9989.  
  9990.  
  9991.  
  9992.  A.1.1
  9993.  
  9994.  
  9995.  discounts ─ Structure
  9996.  
  9997.  -         discounttype  stor_id  lowqty    highqty   discount
  9998.  ────────────────────────────────────────────────────────────────────────────
  9999.  Datatype  varchar(40)   char(4)  smallint  smallint  float
  10000.  
  10001.  Null      not null      null     null      null      not null
  10002.  
  10003.  
  10004.  discounts ─ Contents
  10005.  
  10006.  discounttype                      stor_id   lowqty  highqty  discount
  10007.  ────────────────────────────────────────────────────────────────────────────
  10008.  Initial Customer                  ─         ─       ─        10.5
  10009.  
  10010.  Volume Discount                   ─         100     1000     6.7
  10011.  
  10012.  Customer Discount                 8042      ─       ─        5.0
  10013.  
  10014.  
  10015.  roysched ─ Structure
  10016.  
  10017.  -                                 title_id  lorange  hirange  royalty
  10018.  ────────────────────────────────────────────────────────────────────────────
  10019.  Datatype                          tid        int      int      int
  10020.  
  10021.  Null                              not null   null     null     null
  10022.  
  10023.  Index                             nonclust   ─        ─        ─
  10024.  
  10025.  Table   roysched ─ Contents
  10026.  
  10027. ╓┌─────────┌────────┌─┌────────┌─┌───────────────────────────────────────────╖
  10028.  title_id  lorange    hirange    royalty
  10029.  ────────────────────────────────────────────────────────────────────────────
  10030.  BU1032    0          5000       10
  10031.  BU1032    5001       50000      12
  10032.  PC1035    0          2000       10
  10033.  PC1035    2001       3000       12
  10034.  PC1035    3001       4000       14
  10035.  PC1035    4001       10000      16
  10036.  PC1035    10001      50000      18
  10037.  BU2075    0          1000       10
  10038.  BU2075    1001       3000       12
  10039.  BU2075    3001       5000       14
  10040.  title_id  lorange    hirange    royalty
  10041.  ────────────────────────────────────────────────────────────────────────────
  10042. BU2075    3001       5000       14
  10043.  BU2075    5001       7000       16
  10044.  BU2075    7001       10000      18
  10045.  BU2075    10001      12000      20
  10046.  BU2075    12001      14000      22
  10047.  BU2075    14001      50000      24
  10048.  PS2091    0          1000       10
  10049.  PS2091    1001       5000       12
  10050.  PS2091    5001       10000      14
  10051.  PS2091    10001      50000      16
  10052.  PS2106    0          2000       10
  10053.  PS2106    2001       5000       12
  10054.  PS2106    5001       10000      14
  10055.  PS2106    10001      50000      16
  10056.  MC3021    0          1000       10
  10057.  MC3021    1001       2000       12
  10058.  MC3021    2001       4000       14
  10059.  MC3021    4001       6000       16
  10060.  MC3021    6001       8000       18
  10061.  title_id  lorange    hirange    royalty
  10062.  ────────────────────────────────────────────────────────────────────────────
  10063. MC3021    6001       8000       18
  10064.  MC3021    8001       10000      20
  10065.  MC3021    10001      12000      22
  10066.  MC3021    12001      50000      24
  10067.  TC3218    0          2000       10
  10068.  TC3218    2001       4000       12
  10069.  TC3218    4001       6000       14
  10070.  TC3218    6001       8000       16
  10071.  TC3218    8001       10000      18
  10072.  TC3218    10001      12000      20
  10073.  TC3218    12001      14000      22
  10074.  TC3218    14001      50000      24
  10075.  TC3218    0          2000       10
  10076.  TC3218    2001       4000       12
  10077.  TC3218    4001       6000       14
  10078.  TC3218    6001       8000       16
  10079.  TC3218    8001       10000      18
  10080.  TC3218    10001      12000      20
  10081.  TC3218    12001      14000      22
  10082.  title_id  lorange    hirange    royalty
  10083.  ────────────────────────────────────────────────────────────────────────────
  10084. TC3218    12001      14000      22
  10085.  TC3218    14001      50000      24
  10086.  PC8888    0          5000       10
  10087.  PC8888    5001       10000      12
  10088.  PC8888    10001      15000      14
  10089.  PC8888    15001      50000      16
  10090.  PS7777    0          5000       10
  10091.  PS7777    5001       50000      12
  10092.  PS3333    0          5000       10
  10093.  PS3333    5001       10000      12
  10094.  PS3333    10001      15000      14
  10095.  PS3333    15001      50000      16
  10096.  BU1111    0          4000       10
  10097.  BU1111    4001       8000       12
  10098.  BU1111    8001       10000      14
  10099.  BU1111    12001      16000      16
  10100.  BU1111    16001      20000      18
  10101.  BU1111    20001      24000      20
  10102.  BU1111    24001      28000      22
  10103.  title_id  lorange    hirange    royalty
  10104.  ────────────────────────────────────────────────────────────────────────────
  10105. BU1111    24001      28000      22
  10106.  BU1111    28001      50000      24
  10107.  MC2222    0          2000       10
  10108.  MC2222    2001       4000       12
  10109.  MC2222    4001       8000       14
  10110.  MC2222    8001       12000      16
  10111.  MC2222    8001       12000      16
  10112.  MC2222    12001      20000      18
  10113.  MC2222    20001      50000      20
  10114.  TC7777    0          5000       10
  10115.  TC7777    5001       15000      02
  10116.  TC7777    15001      50000      14
  10117.  TC4203    0          2000       10
  10118.  TC4203    2001       8000       12
  10119.  TC4203    8001       16000      14
  10120.  TC4203    16001      24000      16
  10121.  TC4203    24001      32000      18
  10122.  TC4203    32001      40000      20
  10123.  TC4203    40001      50000      22
  10124.  title_id  lorange    hirange    royalty
  10125.  ────────────────────────────────────────────────────────────────────────────
  10126. TC4203    40001      50000      22
  10127.  BU7832    0          5000       10
  10128.  BU7832    5001       10000      12
  10129.  BU7832    10001      15000      14
  10130.  BU7832    15001      20000      16
  10131.  BU7832    20001      25000      18
  10132.  BU7832    25001      30000      20
  10133.  BU7832    30001      35000      22
  10134.  BU7832    35001      50000      24
  10135.  PS1372    0          10000      10
  10136.  PS1372    10001      20000      12
  10137.  PS1372    20001      30000      14
  10138.  PS1372    30001      40000      16
  10139.  PS1372    40001      50000      18
  10140.  ────────────────────────────────────────────────────────────────────────────
  10141.  
  10142.  
  10143.  Table   authors ─ Structure
  10144.  
  10145.            au_id    au_lname     au_fname    phone     address      city
  10146.  
  10147.  ─────────────────────────────────────────────────────────────────────────────
  10148.  Datatype  id       varchar(40)  varchar(20)  char(12)  varchar(40)  varchar(2
  10149.  
  10150.  Null      not      not null     not null    not null  null         null
  10151.            null
  10152.  
  10153.  Default   ─        ─            ─           UNKNOWN1  ─            ─
  10154.  
  10155.  
  10156.  Index     clust,   nonclust,                ─         ─            ─
  10157.            uniq     composite
  10158.  
  10159.  ─────────────────────────────────────────────────────────────────────────────
  10160.  
  10161.  
  10162.  (1) The default UNKNOWN is inserted if no data is entered.
  10163.  (2) The rule ziprule states that the zip code must match the pattern
  10164.  [0-9][0-9][0-9][0-9][0-9].
  10165.  
  10166.  
  10167.  Table   authors ─ Contents
  10168.  
  10169. ╓┌────────────┌───────────────┌────────────┌─────────┌─────────────┌─────────
  10170.  au_id        au_lname        au_fname     phone     address       city
  10171.  
  10172.  ─────────────────────────────────────────────────────────────────────────────
  10173.  409-56-7008  Bennet          Abraham      415       6223 Bateman  Berkeley
  10174.                                            658-9932  St.
  10175.  
  10176.  213-46-8915  Green           Marjorie     415       309 63rd St.  Oakland
  10177.                                            986-7020  #411
  10178.  
  10179.  238-95-7766  Carson          Cheryl       415       589 Darwin    Berkeley
  10180.                                            548-7723  Ln.
  10181.  
  10182.  998-72-3567  Ringer          Albert       801       67 Seventh    Salt Lake
  10183.                                            826-0752  Av.           City
  10184.  
  10185.  899-46-2035  Ringer          Anne         801       67 Seventh    Salt Lake
  10186.                                            826-0752  Av.           City
  10187.  au_id        au_lname        au_fname     phone     address       city
  10188.  
  10189.                                           826-0752  Av.           City
  10190.  
  10191.  722-51-5454  DeFrance        Michel       219       3 Balding Pl.  Gary
  10192.                                            547-9982
  10193.  
  10194.  807-91-6654  Panteley        Sylvia       301       1956          Rockville
  10195.                                            946-8853  Arlington Dr.
  10196.  
  10197.  893-72-1158  McBadden        Heather      707       301 Putnam    Vacaville
  10198.                                            448-4982
  10199.  
  10200.  724-08-9931  Stringer        Dirk         415       5420          Oakland
  10201.                                            843-2991  Telegraph Av.
  10202.  
  10203.  274-80-9391  Straight        Dick         415       5420 College  Oakland
  10204.                                            834-2919  Av.
  10205.  
  10206.  756-30-7391  Karsen          Livia        415       5720 McAuley  Oakland
  10207.                                            534-9219  St.
  10208.  au_id        au_lname        au_fname     phone     address       city
  10209.  
  10210.                                           534-9219  St.
  10211.  
  10212.  724-80-9391  MacFeather      Stearns      415       44 Upland     Oakland
  10213.                                            354-7128  Hts.
  10214.  
  10215.  427-17-2319  Dull            Ann          415       3410 Blonde   Palo Alto
  10216.                                            836-7128  St.
  10217.  
  10218.  672-71-3249  Yokomoto        Akiko        415       3 Silver Ct.  Walnut
  10219.                                            935-4228                Creek
  10220.  
  10221.  267-41-2394  O'Leary         Michael      408       22 Cleveland  San Jose
  10222.                                            286-2428  Av. #14
  10223.  
  10224.  472-27-2349  Gringlesby      Burt         707       PO Box 792    Covelo
  10225.                                            938-6445
  10226.  
  10227.  527-72-3246  Greene          Morningstar  615       22 Graybar    Nashville
  10228.                                            297-2723  House Rd.
  10229.  au_id        au_lname        au_fname     phone     address       city
  10230.  
  10231.                                           297-2723  House Rd.
  10232.  
  10233.  172-32-1176  White           Johnson      408       10932 Bigge   Menlo
  10234.                                            496-7223  Rd.           Park
  10235.  
  10236.  712-45-1867  del Castillo    Innes        615       2286 Cram Pl.  Ann Arbor
  10237.                                            996-8275  #86
  10238.  
  10239.  846-92-7186  Hunter          Sheryl       415       3410 Blonde   Palo Alto
  10240.                                            836-7128  St.
  10241.  
  10242.  486-29-1786  Locksley        Chastity     415       18 Broadway   San
  10243.                                            585-4620  Av.           Francisco
  10244.  
  10245.  648-92-1872  Blotchet-Halls  Reginald     503       55 Hillsdale  Corvallis
  10246.                                            745-6402  Bl.
  10247.  
  10248.  341-22-1782  Smith           Meander      913       10            Lawrence
  10249.                                            843-0462  Mississippi
  10250.  au_id        au_lname        au_fname     phone     address       city
  10251.  
  10252.                                           843-0462  Mississippi
  10253.                                                      Dr.
  10254.  
  10255.  ─────────────────────────────────────────────────────────────────────────────
  10256.  
  10257.  
  10258.  
  10259.  Table   titles ─ Structure
  10260.  
  10261. ╓┌─────────┌──────────┌────────────┌───────────┌────────┌──────┌──────┌─────┌
  10262.            title_id   title        type        pub_id   price  advan  roya  yt
  10263.                                                                ce     lty   sa
  10264.                                                                             s
  10265.  ─────────────────────────────────────────────────────────────────────────────
  10266.  Datatype  tid        varchar(80)  char(12)    char(4)  money  money  int   in
  10267.  
  10268.  Null      not null   not null     not null    null     null   null   null  nu
  10269.  
  10270.  Default   ─          ─            UNDECIDED1  ─        ─      ─      ─     ─
  10271.            title_id   title        type        pub_id   price  advan  roya  yt
  10272.                                                                ce     lty   sa
  10273.                                                                             s
  10274. Default   ─          ─            UNDECIDED1  ─        ─      ─      ─     ─
  10275.  
  10276.  Rule      ─          ─            ─           ─        ─      ─      ─     ─
  10277.  
  10278.  Trigger   deltitle3  ─            ─           ─        ─      ─      ─     ─
  10279.  
  10280.  Index     clust,     nonclust     ─           ─        ─      ─      ─     ─
  10281.            uniq
  10282.  
  10283.  ─────────────────────────────────────────────────────────────────────────────
  10284.  
  10285.  
  10286.  
  10287.  (1) The default UNDECIDED is inserted if no data is entered in the column.
  10288.  (2) The getdate() function inserts the current date as the default if no
  10289.  data is entered in the column.
  10290.  (3) The deltitle trigger prohibits deleting a title if the title_id is
  10291.  listed in the sales table.
  10292.  
  10293.  
  10294.  Table   titles ─ Contents
  10295.  
  10296. ╓┌───────┌───────────────┌─────────────┌──────┌───────┌──────────┌──────┌────
  10297.  title_  title           type          pub_i  price   advance    royal  ytd_s
  10298.  id                                    d                         ty     ales
  10299.  ─────────────────────────────────────────────────────────────────────────────
  10300.  BU1032  The Busy        business      1389   $19.99  $5000.00   10     4095
  10301.          Executive's
  10302.          Database Guide
  10303.  
  10304.  
  10305.  
  10306.  
  10307.  PC1035  But Is It User  popular_comp  1389   $22.95  $7000.00   16     8780
  10308.          Friendly?
  10309.  
  10310.  
  10311.  
  10312.  
  10313.  title_  title           type          pub_i  price   advance    royal  ytd_s
  10314.  id                                    d                         ty     ales
  10315.  ─────────────────────────────────────────────────────────────────────────────
  10316. 
  10317.  BU2075  You Can Combat  business      0736   $2.99   $10125.00  24     18722
  10318.          Computer
  10319.          Stress!
  10320.  
  10321.  
  10322.  
  10323.  
  10324.  
  10325.  PS2091  Is Anger the    psychology    0736   10.95   $2275.00   12     2045
  10326.          Enemy?
  10327.  
  10328.  
  10329.  
  10330.  
  10331.  PS2106  Life Without    psychology    0736   $7.00   $6000.00   10     111
  10332.          Fear
  10333.  
  10334.  title_  title           type          pub_i  price   advance    royal  ytd_s
  10335.  id                                    d                         ty     ales
  10336.  ─────────────────────────────────────────────────────────────────────────────
  10337. 
  10338.  
  10339.  
  10340.  
  10341.  
  10342.  
  10343.  
  10344.  
  10345.  
  10346.  MC3021  The Gourmet     mod_cook      0877   $2.99   $15000.00  24     22246
  10347.          Microwave
  10348.  
  10349.  
  10350.  
  10351.  TC3218  Onions, Leeks,  trad_cook     0877   $20.95  $7000.00   10     375
  10352.          and Garlic:
  10353.          Cooking
  10354.          Secrets of the
  10355.  title_  title           type          pub_i  price   advance    royal  ytd_s
  10356.  id                                    d                         ty     ales
  10357.  ─────────────────────────────────────────────────────────────────────────────
  10358.         Secrets of the
  10359.          Mediterranean
  10360.  
  10361.  
  10362.  MC3026  The Psychology  UNDECIDED     0877   NULL    NULL       NULL   NULL
  10363.          of Computer
  10364.          Cooking
  10365.  
  10366.  PC8888  Secrets of      popular_comp  1389   $20.00  $8000.00   10     4095
  10367.          Silicon
  10368.          Valley
  10369.  
  10370.  
  10371.  
  10372.  
  10373.  PS7777  Emotional       psychology    0736   $7.99   $4000.00   10     3336
  10374.          Security:
  10375.          A New
  10376.  title_  title           type          pub_i  price   advance    royal  ytd_s
  10377.  id                                    d                         ty     ales
  10378.  ─────────────────────────────────────────────────────────────────────────────
  10379.         A New
  10380.          Algorithm
  10381.  
  10382.  
  10383.  
  10384.  
  10385.  
  10386.  PS3333  Prolonged Data  psychology    0736   $19.99  $2000.00   10     4072
  10387.          Deprivation:
  10388.          Four Case
  10389.          Studies
  10390.  
  10391.  
  10392.  
  10393.  
  10394.  BU1111  Cooking with    business      1389   $11.95  $5000.00   10     3876
  10395.          Computers:
  10396.          Surreptitious
  10397.  title_  title           type          pub_i  price   advance    royal  ytd_s
  10398.  id                                    d                         ty     ales
  10399.  ─────────────────────────────────────────────────────────────────────────────
  10400.         Surreptitious
  10401.          Balance Sheets
  10402.  
  10403.  MC2222  Silicon Valley  mod_cook      0877   $19.99  $0.00      12     2032
  10404.          Gastronomic
  10405.          Treats
  10406.  
  10407.  
  10408.  
  10409.  
  10410.  
  10411.  TC7777  Sushi, Anyone?  trad_cook     0877   $14.99  $8000.00   10     4095
  10412.  
  10413.  
  10414.  
  10415.  
  10416.  
  10417.  
  10418.  title_  title           type          pub_i  price   advance    royal  ytd_s
  10419.  id                                    d                         ty     ales
  10420.  ─────────────────────────────────────────────────────────────────────────────
  10421. 
  10422.  
  10423.  
  10424.  
  10425.  
  10426.  TC4203  Fifty Years in  trad_cook     0877   $11.95  $4000.00   14     15096
  10427.          Buckingham
  10428.          Palace
  10429.          Kitchens
  10430.  
  10431.  
  10432.  
  10433.  BU7832  Straight Talk   business      1389   $19.99  $5000.00   10     4095
  10434.          About
  10435.          Computers
  10436.  
  10437.  
  10438.  
  10439.  title_  title           type          pub_i  price   advance    royal  ytd_s
  10440.  id                                    d                         ty     ales
  10441.  ─────────────────────────────────────────────────────────────────────────────
  10442. 
  10443.  PS1372  Computer        psychology    0877   $21.59  $7000.00   10     375
  10444.          Phobic and
  10445.          Non-Phobic
  10446.          Individuals:
  10447.          Behavior
  10448.          Variations
  10449.  
  10450.  
  10451.  
  10452.  PC9999  Net Etiquette   popular_comp  1389   NULL    NULL       NULL   NULL
  10453.  
  10454.  
  10455.  
  10456.  ─────────────────────────────────────────────────────────────────────────────
  10457.  
  10458.  
  10459.  
  10460.  The pubs database contains the following database objects:
  10461.  
  10462.  
  10463.  Rules
  10464.  
  10465.  
  10466.  pub_idrule
  10467.  
  10468.    create rule pub_idrule
  10469.     as @pub_id in ("1389", "0736", "0877", "1622", "1756")
  10470.     or @pub_id like "99[0-9][0-9]"
  10471.  
  10472.  
  10473.  ziprule
  10474.  
  10475.    create rule ziprule
  10476.     as @zip like "[0-9][0-9][0-9][0-9][0-9]"
  10477.  
  10478.  
  10479.  Trigger
  10480.  
  10481.  
  10482.  deltitle
  10483.  
  10484.    create trigger deltitle
  10485.     on titles
  10486.     for delete
  10487.     as
  10488.     if (select count(*) from deleted, sales
  10489.     where sales.title_id = deleted.title_id) > 0
  10490.      begin
  10491.      rollback transaction
  10492.      print "You can't delete a title with sales."
  10493.      end
  10494.  
  10495.  
  10496.  Stored Procedure
  10497.  
  10498.  
  10499.  byroyalty
  10500.  
  10501.    create procedure byroyalty percentage int
  10502.     as
  10503.     select au_id from titleauthor
  10504.     where titleauthor.royaltyper = percentage
  10505.  
  10506.  
  10507.  View
  10508.  
  10509.  
  10510.  titleview
  10511.  
  10512.    create view titleview
  10513.     as
  10514.     select title, au_ord, au_lname, price, ytd_sales, pub_id
  10515.     from authors, titles, titleauthor
  10516.     where authors.au_id = titleauthor.au_id
  10517.     and titles.title_id = titleauthor.title_id
  10518.  
  10519.  
  10520.  Defaults
  10521.  
  10522.  
  10523.  datedflt
  10524.  
  10525.    create default datedflt
  10526.     as getdate( )
  10527.  
  10528.  
  10529.  phonedflt
  10530.  
  10531.    create default phonedflt
  10532.     as "UNKNOWN"
  10533.  
  10534.  
  10535.  typedflt
  10536.  
  10537.    create default typedflt  as "UNDECIDED"
  10538.  
  10539.  Figure A.1 shows the structure of the pubs sample database.
  10540.  
  10541.  (This figure may be found in the printed book.)
  10542.  
  10543.  
  10544.  
  10545.  
  10546.  
  10547.  
  10548.  Appendix B  System Tables
  10549.  ────────────────────────────────────────────────────────────────────────────
  10550.  
  10551.  System tables define the structure of the database. All system tables are
  10552.  found in the master database. Some system tables are found in all databases;
  10553.  they are automatically created when the CREATE DATABASE statement is
  10554.  executed.
  10555.  
  10556.  The following system tables exist in all databases:
  10557.  
  10558.  ────────────────────────────────────────────────────────────────────────────
  10559.  sysalternates
  10560.    One row for each SQL Server user mapped to a database user
  10561.  
  10562.  syscolumns
  10563.    One row for each column in a table or view, and for each parameter in a
  10564.    stored procedure
  10565.  
  10566.  syscomments
  10567.    One or more rows for each view, rule, default, trigger, and stored
  10568.    procedure, giving an SQL definition statement
  10569.  
  10570.  sysdepends
  10571.    One row for each procedure, view, or table that is referenced by a
  10572.    procedure, view, or trigger
  10573.  
  10574.  sysindexes
  10575.    One row for each clustered index, nonclustered index, and table with no
  10576.    indexes
  10577.  
  10578.  syskeys
  10579.    One row for each foreign or primary key; set by user (not maintained by
  10580.    SQL Server)
  10581.  
  10582.  syslogs
  10583.    The transaction log
  10584.  
  10585.  sysobjects
  10586.    One row for each table, view, stored procedure, rule, trigger default,
  10587.    log, and (in tempdb only) temporary object
  10588.  
  10589.  sysprocedures
  10590.    One row for each view, rule, default, trigger, and stored procedure,
  10591.    giving an internal definition
  10592.  
  10593.  sysprotects
  10594.    User permissions information
  10595.  
  10596.  syssegments
  10597.    One row for each segment (named collection of disk pieces)
  10598.  
  10599.  systypes
  10600.    One row for each system-supplied and user-defined datatype
  10601.  
  10602.  sysusers
  10603.    One row for each user allowed in the database
  10604.  
  10605.  ────────────────────────────────────────────────────────────────────────────
  10606.  The following system tables exist in the master database only:
  10607.  
  10608.  ────────────────────────────────────────────────────────────────────────────
  10609.  sysconfigures
  10610.    One row for each user-settable configuration option
  10611.  
  10612.  syscurconfigs
  10613.    Information about configuration options currently being used by SQL Server
  10614.  
  10615.  sysdatabases
  10616.    One row for each database on SQL Server
  10617.  
  10618.  sysdevices
  10619.    One row for each disk dump device, disk for database device, and disk
  10620.    partition for databases
  10621.  
  10622.  syslocks
  10623.    Information about active locks
  10624.  
  10625.  syslogins
  10626.    One row for each valid SQL Server user account
  10627.  
  10628.  sysmessages
  10629.    One row for each system error or warning
  10630.  
  10631.  sysprocesses
  10632.    Information about server processes
  10633.  
  10634.  sysusages
  10635.    One row for each disk piece allocated to a database
  10636.  
  10637.  ────────────────────────────────────────────────────────────────────────────
  10638.  In the pages that follow, each system table is described in more detail.
  10639.  Each table's columns are listed and described, and their datatypes are
  10640.  given. Finally, each table's indexes and the system procedures that
  10641.  reference it are listed.
  10642.  
  10643.  The word reserved in the column description means that the column is not
  10644.  currently used by SQL Server.
  10645.  
  10646.  Permissions for use of the system tables can be controlled by the Database
  10647.  Owner, just like permissions on any other tables.
  10648.  
  10649.  The SQL Server setup program sets up permissions so that all users can read
  10650.  the system tables, except for a few fields, like syslogins.passwd.
  10651.  
  10652.  All direct updates on system tables are disallowed by default, however, even
  10653.  for the Database Owner, because SQL Server has supplied system procedures to
  10654.  make any updates and additions to system tables that are normally needed.
  10655.  
  10656.  You can change the default and allow direct updates to the system tables if
  10657.  for some reason it becomes necessary to modify them in a way that has not
  10658.  been anticipated by SQL Server (and that therefore cannot be accomplished
  10659.  with a system procedure). This is accomplished by resetting the
  10660.  configuration option called allow updates with the sp_configure system
  10661.  procedure and the RECONFIGURE statement. For information on sp_configure,
  10662.  see the SQL Server Language Reference.
  10663.  
  10664.  ────────────────────────────────────────────────────────────────────────────
  10665.  WARNING
  10666.  
  10667.  Some entries in some master database tables should not be altered by any
  10668.  user under any circumstances. For example, do not access syslogs in any way.
  10669.  Doing so may make it impossible for SQL Server to recover correctly in case
  10670.  of a system failure. In addition, an attempt to delete all rows from syslogs
  10671.  puts SQL Server into an infinite loop that eventually fills up the entire
  10672.  database.
  10673.  ────────────────────────────────────────────────────────────────────────────
  10674.  
  10675.  
  10676.  sysalternates (all databases)
  10677.  
  10678.  
  10679.  Description
  10680.  
  10681.  Contains one row for each SQL Server user mapped (or with an alias) to a
  10682.  user of the current database. When a user tries to access a database, SQL
  10683.  Server looks for a valid uid entry in sysusers. If none is found, it looks
  10684.  in sysalternates.suid. If the user's suid is found there, he or she is
  10685.  treated as the database user whose suid is listed in sysalternates.altsuid.
  10686.  
  10687.  
  10688.  When SQL Server is installed, there are no entries in sysalternates.
  10689.  
  10690.  Column   Datatype  Description
  10691.  ────────────────────────────────────────────────────────────────────────────
  10692.  suid     smallint  Server user ID of user being mapped
  10693.  altsuid  smallint  Server user ID of user to whom another user is mapped
  10694.  ────────────────────────────────────────────────────────────────────────────
  10695.  
  10696.  
  10697.  Indexes
  10698.  
  10699.  Unique clustered index on suid
  10700.  
  10701.  
  10702.  Referenced by System Procedures
  10703.  
  10704.  sp_addalias, sp_adduser, sp_changedbowner, sp_dropalias, sp_dropuser,
  10705.  sp_helpuser
  10706.  
  10707.  
  10708.  syscolumns (all databases)
  10709.  
  10710.  
  10711.  Description
  10712.  
  10713.  Contains one row for every column in every table and view, and a row for
  10714.  each parameter in a stored procedure.
  10715.  
  10716. ╓┌─────────┌─────────────┌───────────────────────────────────────────────────╖
  10717.  Column    Datatype      Description
  10718.  ────────────────────────────────────────────────────────────────────────────
  10719.  id        int           ID of the table to which this column belongs or of
  10720.                          the stored procedure with which this parameter is
  10721.                          associated
  10722.  
  10723.  number    smallint      Subprocedure number when the procedure is grouped
  10724.                          (0 for nonprocedure entries)
  10725.  
  10726.  colid     tinyint       Column ID
  10727.  
  10728.  status    tinyint       Indicates the unique position for bit columns and
  10729.                          whether null values are legal in this column
  10730.  
  10731.  type      tinyint       Physical storage type; copied from systypes
  10732.  
  10733.  Column    Datatype      Description
  10734.  ────────────────────────────────────────────────────────────────────────────
  10735. 
  10736.  length    tinyint       Physical length of data; copied from systypes or
  10737.                          supplied by user
  10738.  
  10739.  offset    smallint      Offset into the row where this column appears; if
  10740.                          negative, variable-length column
  10741.  
  10742.  usertype  smallint      User type ID; copied from systypes
  10743.  
  10744.  cdefault  int           ID of the stored procedure that generates default
  10745.                          value for this column
  10746.  
  10747.  domain    int           ID of the stored procedure that contains the rule
  10748.                          for this column
  10749.  
  10750.  name      sysname       Column name
  10751.  
  10752.  printfmt  varchar(255)  reserved
  10753.  
  10754.  Column    Datatype      Description
  10755.  ────────────────────────────────────────────────────────────────────────────
  10756. 
  10757.  ────────────────────────────────────────────────────────────────────────────
  10758.  
  10759.  
  10760.  
  10761.  
  10762.  Indexes
  10763.  
  10764.  Unique clustered index on id, number, and colid
  10765.  
  10766.  
  10767.  Referenced by System Procedures
  10768.  
  10769.  sp_bindefault, sp_bindrule, sp_commonkey, sp_droptype, sp_foreignkey,
  10770.  sp_help, sp_helpjoins, sp_helprotect, sp_primarykey, sp_rename,
  10771.  sp_unbindefault, sp_unbindrule
  10772.  
  10773.  
  10774.  syscomments (all databases)
  10775.  
  10776.  
  10777.  Description
  10778.  
  10779.  Contains entries for each view, rule, default, trigger, and stored
  10780.  procedure. The text field contains the original SQL definition statements.
  10781.  Since text is often longer than 255 characters, entries often span rows.
  10782.  Each object can occupy up to 255 rows.
  10783.  
  10784. ╓┌─────────┌─────────────┌───────────────────────────────────────────────────╖
  10785.  Column    Datatype      Description
  10786.  ────────────────────────────────────────────────────────────────────────────
  10787.  id        int           Object ID to which this text applies
  10788.  
  10789.  number    smallint      Grouped (0 for nonprocedure entries)
  10790.  
  10791.  colid     tinyint       Column ID if this entry is a column; 0 otherwise
  10792.  
  10793.  texttype  smallint      0 System-supplied comment (for views, rules,
  10794.                          defaults, triggers, and stored procedures)
  10795.                          1 User-supplied comment (users can add entries
  10796.  Column    Datatype      Description
  10797.  ────────────────────────────────────────────────────────────────────────────
  10798.                         1 User-supplied comment (users can add entries
  10799.                          that describe an object or column)
  10800.  
  10801.  language  smallint      reserved
  10802.  
  10803.  text      varchar(255)  Actual text of SQL definition statement
  10804.  
  10805.  ────────────────────────────────────────────────────────────────────────────
  10806.  
  10807.  
  10808.  
  10809.  
  10810.  Indexes
  10811.  
  10812.  Unique clustered index on id, number, colid, and texttype
  10813.  
  10814.  
  10815.  Referenced by System Procedures
  10816.  
  10817.  sp_helptext
  10818.  
  10819.  
  10820.  sysconfigures (master database only)
  10821.  
  10822.  
  10823.  Description
  10824.  
  10825.  Contains one row for each user-settable configuration option. It contains
  10826.  the configuration options that were defined before the latest SQL Server
  10827.  startup plus any dynamic configuration options that were set since the
  10828.  latest SQL Server startup.
  10829.  
  10830.  The contents of sysconfigures is as follows:
  10831.  
  10832. ╓┌───────┌───────────┌───────┌────────────────────────────┌──────────────────╖
  10833.  ────────────────────────────────────────────────────────────────────────────
  10834.          config      value   comment                      status
  10835.  
  10836.          101         5       Maximum recovery interval    1
  10837.                              in minutes
  10838.  ────────────────────────────────────────────────────────────────────────────
  10839.                             in minutes
  10840.  
  10841.          102         0       Allow updates to system      1
  10842.                              tables
  10843.  
  10844.          103         10      Number of user connections   0
  10845.                              allowed
  10846.  
  10847.          104         1518    Size of available physical   0
  10848.                              memory in 2k pages
  10849.  
  10850.          105         10      Number of open databases     0
  10851.                              allowed among all users
  10852.  
  10853.          106         5000    Number of locks for all      0
  10854.                              users
  10855.  
  10856.          107         500     Number of open database      0
  10857.                              objects
  10858.  
  10859.  ────────────────────────────────────────────────────────────────────────────
  10860. 
  10861.          108         20      Percent of remaining memory  0
  10862.                              used for procedure cache
  10863.  
  10864.          109         0       Default fill factor          0
  10865.                              percentage
  10866.  
  10867.          110         100     Average time slice per       0
  10868.                              process in milliseconds
  10869.  
  10870.          111         2       Default database size in     0
  10871.                              megabytes
  10872.  
  10873.          112         0       Media retention period in    0
  10874.                              days
  10875.  
  10876.          113         0       Recovery flags               0
  10877.  
  10878.          114         0       Serial Number                0
  10879.  
  10880.  ────────────────────────────────────────────────────────────────────────────
  10881. 
  10882.  
  10883.          (14 rows
  10884.          affected)
  10885.  
  10886.  
  10887.  
  10888.  Column   Datatype      Description
  10889.  ────────────────────────────────────────────────────────────────────────────
  10890.  config   smallint      Configuration variable number
  10891.  
  10892.  value    int           User-modifiable value for the variable (being used
  10893.                         by SQL Server only if RECONFIGURE has been executed)
  10894.  
  10895.  comment  varchar(255)  Explanation of the configuration option
  10896.  
  10897.  status   varchar(2)    1 dynamic, the variable takes effect when
  10898.                         RECONFIGURE is executed
  10899.                         0 The variable takes effect when SQL Server is
  10900.                         restarted
  10901.  
  10902.  ────────────────────────────────────────────────────────────────────────────
  10903.  
  10904.  
  10905.  ────────────────────────────────────────────────────────────────────────────
  10906.  NOTE
  10907.  
  10908.  The values shown above are created when you install SQL Server with the
  10909.  setup program. If you install SQL Server with the bldmastr utility program,
  10910.  the values column will be different. bldmastr creates a 0 in the values
  10911.  column to indicate that the default value is in effect.
  10912.  ────────────────────────────────────────────────────────────────────────────
  10913.  
  10914.  
  10915.  Indexes
  10916.  
  10917.  Unique clustered index on config
  10918.  
  10919.  
  10920.  Referenced by System Procedures
  10921.  
  10922.  sp_configure
  10923.  
  10924.  
  10925.  syscurconfigs (master database only)
  10926.  
  10927.  
  10928.  Description
  10929.  
  10930.  Is built dynamically when queried. It contains an entry for each of the
  10931.  configuration options, as does sysconfigures, but with the current values.
  10932.  In addition, it contains four entries that describe the configuration
  10933.  structure.
  10934.  
  10935.  The contents of syscurconfigs is as follows:
  10936.  
  10937. ╓┌───────┌───────────┌───────┌────────────────────────────┌──────────────────╖
  10938.  ────────────────────────────────────────────────────────────────────────────
  10939.          config      value   comment                      status
  10940.  
  10941.          1           1       Major revision number of     0
  10942.                              config data
  10943.  ────────────────────────────────────────────────────────────────────────────
  10944.                             config data
  10945.  
  10946.          2           0       Minor revision number of     0
  10947.                              config data
  10948.  
  10949.          3           1       Reconfigure revision number  0
  10950.                              of config data
  10951.  
  10952.          4           2       Configuration boot source    0
  10953.  
  10954.          101         5       Maximum recovery interval
  10955.                              in minutes 1
  10956.  
  10957.          102         0       Allow updates to system      1
  10958.                              tables
  10959.  
  10960.          103         10      Number of user connections   0
  10961.                              allowed
  10962.  
  10963.          104         1518    Size of available physical   0
  10964.  ────────────────────────────────────────────────────────────────────────────
  10965.         104         1518    Size of available physical   0
  10966.                              memory in 2k pages
  10967.  
  10968.          105         10      Number of open databases     0
  10969.                              allowed among all users
  10970.  
  10971.          106         5000    Number of locks for all      0
  10972.                              users
  10973.  
  10974.          107         500     Number of open database      0
  10975.                              objects
  10976.  
  10977.          108         20      Percent of remaining memory  0
  10978.                              used for procedure cache
  10979.  
  10980.          109         0       Default fill factor          0
  10981.                              percentage
  10982.  
  10983.          110         100     Average time slice per       0
  10984.                              process in milliseconds
  10985.  ────────────────────────────────────────────────────────────────────────────
  10986.                             process in milliseconds
  10987.  
  10988.          111         2       Default database size in     0
  10989.                              megabytes
  10990.  
  10991.          112         0       Media retention period in    0
  10992.                              days
  10993.  
  10994.          113         0       Recovery flags               0
  10995.  
  10996.          114         666666  Serial Number                0
  10997.  
  10998.  
  10999.          (18 rows
  11000.          affected)
  11001.  
  11002.  
  11003.  
  11004.  
  11005.  Referenced by System Procedures
  11006.  
  11007.  sp_configure
  11008.  
  11009.  
  11010.  sysdatabases (master database only)
  11011.  
  11012.  
  11013.  Description
  11014.  
  11015.  Contains one row for each database on SQL Server. When SQL Server is
  11016.  installed, sysdatabases contains entries for the master database, the model
  11017.  database, and the tempdb temporary database.
  11018.  
  11019. ╓┌────────┌─────────┌────────────────────────────────────────────────────────╖
  11020.  Column   Datatype  Description
  11021.  ────────────────────────────────────────────────────────────────────────────
  11022.  name     sysname   Name of the database
  11023.  
  11024.  dbid     smallint  Database ID
  11025.  
  11026.  suid     smallint  Server user ID of database creator
  11027.  Column   Datatype  Description
  11028.  ────────────────────────────────────────────────────────────────────────────
  11029. suid     smallint  Server user ID of database creator
  11030.  
  11031.  mode     smallint  Used internally for locking a database while it is
  11032.                     being created
  11033.  
  11034.  status   smallint  Control bits, some of which can be set by the user with
  11035.                     sp_dboption (read only, dbo only, single user, and so
  11036.                     on):
  11037.                     0x40  select into/bulkcopy; set with sp_dboption
  11038.                     0x08  truncate log on chkpt; set with sp_dboption
  11039.                     0x10  no chkpt on recovery; set with sp_dboption
  11040.                     0x20  Crashed while database was being loaded;
  11041.                       instructs recovery not to proceed
  11042.                     0x100  Database is suspect; cannot be opened or used in
  11043.                     its present state and can be dropped only with
  11044.                       DBCC   DBREPAIR
  11045.                     0x400  Read only; set with sp_dboption
  11046.                     0x800  dbo use only; set with sp_dboption
  11047.                     0x1000 Single user; set with sp_dboption
  11048.  Column   Datatype  Description
  11049.  ────────────────────────────────────────────────────────────────────────────
  11050.                    0x1000 Single user; set with sp_dboption
  11051.                     0x4000  dbname has changed
  11052.  
  11053.  version  smallint  Version of SQL Server code under which database was
  11054.                     created
  11055.  
  11056.  crdate   datetime  Creation date
  11057.  
  11058.  ────────────────────────────────────────────────────────────────────────────
  11059.  
  11060.  
  11061.  
  11062.  
  11063.  Indexes
  11064.  
  11065.  Unique clustered index on name Unique nonclustered index on dbid
  11066.  
  11067.  
  11068.  Referenced by System Procedures
  11069.  
  11070.  sp_addlogin, sp_changedbowner, sp_dboption, sp_defaultdb, sp_depends,
  11071.  sp_helpdb, sp_logdevice, sp_renamedb
  11072.  
  11073.  
  11074.  sysdepends (all databases)
  11075.  
  11076.  
  11077.  Description
  11078.  
  11079.  Contains one row for each procedure, view, or table that is referenced by a
  11080.  procedure, view, or trigger.
  11081.  
  11082. ╓┌──────────┌─────────┌──────────────────────────────────────────────────────╖
  11083.  Column     Datatype  Description
  11084.  ────────────────────────────────────────────────────────────────────────────
  11085.  id         int       Object ID
  11086.  number     smallint  Procedure number
  11087.  depid      int       Dependent object ID
  11088.  depnumber  smallint  Dependent procedure number
  11089.  depdbid              Reserved for future use
  11090.  Column     Datatype  Description
  11091.  ────────────────────────────────────────────────────────────────────────────
  11092. depdbid              Reserved for future use
  11093.  depsiteid            Reserved for future use
  11094.  status     smallint  Internal status information
  11095.  selall     bit       On if object is used in SELECT * statement
  11096.  resultobj  bit       On if object is being updated
  11097.  readobj    bit       On if object is being read
  11098.  ────────────────────────────────────────────────────────────────────────────
  11099.  
  11100.  
  11101.  
  11102.  Indexes
  11103.  
  11104.  Clustered index on id, number, depid, depnumber, dpedbid, and depsiteid
  11105.  
  11106.  
  11107.  Referenced by System Procedures
  11108.  
  11109.  sp_depends
  11110.  
  11111.  
  11112.  sysdevices (master database only)
  11113.  
  11114.  
  11115.  Description
  11116.  
  11117.  Contains one row for each disk dump device, diskette dump device, and
  11118.  database device. When SQL Server is installed, there are four entries in
  11119.  sysdevices: one for the master database device (for databases), one for a
  11120.  disk dump device, and two for diskette dump devices.
  11121.  
  11122. ╓┌──────────┌─────────────┌──────────────────────────────────────────────────╖
  11123.  Column     Datatype      Description
  11124.  ────────────────────────────────────────────────────────────────────────────
  11125.  low        int           First virtual page number on database device (not
  11126.                           used for dump devices)
  11127.  
  11128.  high       int           Last virtual page number on database device (not
  11129.                           used for dump devices)
  11130.  
  11131.  status     smallint      Indicates whether it is to be used as a default:
  11132.  Column     Datatype      Description
  11133.  ────────────────────────────────────────────────────────────────────────────
  11134. status     smallint      Indicates whether it is to be used as a default:
  11135.                            2 Physical database device for database storage
  11136.                            3 Physical database device for default database
  11137.                             storage
  11138.                           16 Dump device (either disk or diskette)
  11139.                           24 Dump device (either disk or diskette);
  11140.                             skip ANSI labels
  11141.  
  11142.  cntrltype  smallint      Controller type (0 if database device, 2 if hard
  11143.                           disk dump device, 3-4 if diskette dump device)
  11144.  
  11145.  name       sysname       Logical name of dump device or database device
  11146.  
  11147.  phyname    varchar(127)  Name of physical database device or dump device
  11148.  
  11149.  ────────────────────────────────────────────────────────────────────────────
  11150.  
  11151.  
  11152.  
  11153.  
  11154.  Indexes
  11155.  
  11156.  Unique clustered index on name
  11157.  
  11158.  
  11159.  Referenced by System Procedures
  11160.  
  11161.  sp_addumpdevice, sp_diskdefault, sp_dropdumpdevice, sp_helpdevice,
  11162.  sp_logdevice
  11163.  
  11164.  
  11165.  sysindexes (all databases)
  11166.  
  11167.  
  11168.  Description
  11169.  
  11170.  Contains one row for each clustered index, one row for each nonclustered
  11171.  index, and one row for each table that has no clustered index.
  11172.  
  11173.  The columns dpages, reserved, used, and rows are maintained only if the row
  11174.  describes a table or clustered index.
  11175.  
  11176. ╓┌─────────────┌───────────────┌─────────────────────────────────────────────╖
  11177.  Column        Datatype        Description
  11178.  ────────────────────────────────────────────────────────────────────────────
  11179.  name          sysname         Index or table name
  11180.  
  11181.  id            int             ID of table or ID of table to which index
  11182.                                belongs
  11183.  
  11184.  indid         smallint        0 if table, 1 if clustered index, >1 if
  11185.                                nonclustered
  11186.  
  11187.  dpages        int             Number of data pages used (if entry is a
  11188.                                table or clustered index)
  11189.  
  11190.  reserved      int             Number of pages allocated (if entry is a
  11191.                                table or clustered index)
  11192.  
  11193.  used          int             Number of data and index pages (if entry is
  11194.                                a clustered index)
  11195.  Column        Datatype        Description
  11196.  ────────────────────────────────────────────────────────────────────────────
  11197.                               a clustered index)
  11198.  
  11199.  rows          int             Number of rows (if entry is a table or
  11200.                                clustered index)
  11201.  
  11202.  first         int             Pointer to first data or leaf page
  11203.  
  11204.  root          int             Pointer to root page if entry is an index;
  11205.                                pointer to last page if entry is a table
  11206.  
  11207.  distribution  int             Pointer to distribution page (if entry is an
  11208.                                index)
  11209.  
  11210.  usagecnt      int             reserved
  11211.  
  11212.  segment       smallint        Number of segment in which this object
  11213.                                resides
  11214.  
  11215.  status        smallint        Internal system status information:
  11216.  Column        Datatype        Description
  11217.  ────────────────────────────────────────────────────────────────────────────
  11218. status        smallint        Internal system status information:
  11219.                                0x1 Abort command if attempt to insert
  11220.                                 duplicate key
  11221.                                0x2 Unique index
  11222.                                0x4 Abort command if attempt to insert
  11223.                                 duplicate row
  11224.                                0x10 Clustered index
  11225.                                0x40 Index allows duplicate rows
  11226.  
  11227.  rowpage       smallint        Maximum number of rows per page
  11228.  
  11229.  minlen        smallint        Minimum size of a row
  11230.  
  11231.  maxlen        smallint        Maximum size of a row
  11232.  
  11233.  maxirow       smallint        Maximum size of a nonleaf index row
  11234.  
  11235.  keycnt        smallint        Number of keys
  11236.  
  11237.  Column        Datatype        Description
  11238.  ────────────────────────────────────────────────────────────────────────────
  11239. 
  11240.  keys1         varbinary(255)  Description of key columns (if entry is an
  11241.                                index)
  11242.  
  11243.  keys2         varbinary(255)  Description of key columns (if entry is an
  11244.                                index)
  11245.  
  11246.  ────────────────────────────────────────────────────────────────────────────
  11247.  
  11248.  
  11249.  
  11250.  
  11251.  Indexes
  11252.  
  11253.  Unique clustered index on id and indid
  11254.  
  11255.  
  11256.  Referenced by System Procedures
  11257.  
  11258.  sp_helpindex, sp_spaceused
  11259.  
  11260.  
  11261.  syskeys (all databases)
  11262.  
  11263.  
  11264.  Description
  11265.  
  11266.  Contains one row for each foreign or primary key.
  11267.  
  11268. ╓┌────────┌─────────┌────────────────────────────────────────────────────────╖
  11269.  Column   Datatype  Description
  11270.  ────────────────────────────────────────────────────────────────────────────
  11271.  id       int       int null
  11272.  type     smallint  Record type
  11273.  depid    int null  Dependent object ID
  11274.  keycnt   int       Number of non-null keys
  11275.  size     int null  reserved
  11276.  key1     int null  Column ID
  11277.  key2     int null  Column ID
  11278.  key3     int null  Column ID
  11279.  Column   Datatype  Description
  11280.  ────────────────────────────────────────────────────────────────────────────
  11281. key3     int null  Column ID
  11282.  key4     int null  Column ID
  11283.  key5     int null  Column ID
  11284.  key6     int null  Column ID
  11285.  key7     int null  Column ID
  11286.  key8     int null  Column ID
  11287.  depkey1  int null  Column ID
  11288.  depkey2  int null  Column ID
  11289.  depkey3  int null  Column ID
  11290.  depkey4  int null  Column ID
  11291.  depkey5  int null  Column ID
  11292.  depkey6  int null  Column ID
  11293.  depkey7  int null  Column ID
  11294.  depkey8  int null  Column ID
  11295.  ────────────────────────────────────────────────────────────────────────────
  11296.  
  11297.  
  11298.  
  11299.  Indexes
  11300.  
  11301.  Clustered index on id
  11302.  
  11303.  
  11304.  Referenced by System Procedures
  11305.  
  11306.  sp_commonkey, sp_dropkey, sp_foreignkey, sp_helpkey, sp_helpjoins,
  11307.  sp_primarykey
  11308.  
  11309.  
  11310.  syslocks (master database only)
  11311.  
  11312.  
  11313.  Description
  11314.  
  11315.  Contains information about active locks. The syslocks system table is not a
  11316.  standard table. Rather, it is built dynamically when queried by a user. No
  11317.  updates to syslocks are allowed.
  11318.  
  11319. ╓┌───────┌─────────┌─────────────────────────────────────────────────────────╖
  11320.  Column  Datatype  Description
  11321.  Column  Datatype  Description
  11322.  ────────────────────────────────────────────────────────────────────────────
  11323.  id      int       Table ID
  11324.  
  11325.  dbid    smallint  Database ID
  11326.  
  11327.  page    int       Page number
  11328.  
  11329.  type    smallint  Type of lock:
  11330.                    1 Exclusive table lock
  11331.                    2 Shared table lock
  11332.                    3 Exclusive intent lock (will do page locking on
  11333.                     indicated pages)
  11334.                    4 Shared intent lock
  11335.                    5 Exclusive page lock
  11336.                    6 Shared page lock
  11337.                    7 Update page lock (changes to exclusive if page is
  11338.                     actually modified)
  11339.                    8 Exclusive extent lock
  11340.                    9 Shared extent lock
  11341.                    0x100 Lock is blocking another process
  11342.  Column  Datatype  Description
  11343.  ────────────────────────────────────────────────────────────────────────────
  11344.                   0x100 Lock is blocking another process
  11345.                    0x200 Demand lock
  11346.  
  11347.  spid    smallint  ID of process that holds the lock
  11348.  
  11349.  ────────────────────────────────────────────────────────────────────────────
  11350.  
  11351.  
  11352.  
  11353.  
  11354.  Indexes
  11355.  
  11356.  None
  11357.  
  11358.  
  11359.  Referenced by System Procedures
  11360.  
  11361.  sp_lock
  11362.  
  11363.  
  11364.  syslogins (master database only)
  11365.  
  11366.  
  11367.  Description
  11368.  
  11369.  Contains one row for each valid SQL Server user account. When SQL Server is
  11370.  installed, syslogins contains one entry, in which the name is sa, the suid
  11371.  is 1, and the password is null.
  11372.  
  11373. ╓┌────────────┌─────────────┌────────────────────────────────────────────────╖
  11374.  Column       Datatype      Description
  11375.  ────────────────────────────────────────────────────────────────────────────
  11376.  suid         smallint      Server user ID
  11377.  
  11378.  status       smallint      reserved
  11379.  
  11380.  accdate      datetime      reserved
  11381.  
  11382.  totcpu       int           reserved
  11383.  
  11384.  Column       Datatype      Description
  11385.  ────────────────────────────────────────────────────────────────────────────
  11386. 
  11387.  totio        int           reserved
  11388.  
  11389.  spacelimit   int           reserved
  11390.  
  11391.  timelimit    int           reserved
  11392.  
  11393.  resultlimit  int           reserved
  11394.  
  11395.  dbname       sysname       Name of database to put user into when
  11396.                             connection is established
  11397.  
  11398.  name         sysname       Login ID of user
  11399.  
  11400.  password     sysname null  Password of user (may be null)
  11401.  
  11402.  ────────────────────────────────────────────────────────────────────────────
  11403.  
  11404.  
  11405.  
  11406.  
  11407.  Indexes
  11408.  
  11409.  Unique clustered index on suid Unique nonclustered index on name
  11410.  
  11411.  
  11412.  Referenced by System Procedures
  11413.  
  11414.  sp_addalias, sp_addlogin, sp_adduser, sp_changedbowner, sp_defaultdb,
  11415.  sp_defdb, sp_droplogin, sp_helpdb, sp_helpuser, sp_password
  11416.  
  11417.  
  11418.  syslogs (all databases)
  11419.  
  11420.  
  11421.  Description
  11422.  
  11423.  Contains the transaction log. It is used by SQL Server for recovery and
  11424.  roll-forward; it is not used by system users.
  11425.  
  11426.  You cannot delete from, insert into, or update syslogs. Every data
  11427.  modification operation is logged, so before you can change syslogs, the
  11428.  change must be logged. This means that a change operation on syslogs adds a
  11429.  row to syslogs, which then must be logged, adding another row to syslogs,
  11430.  and so on, producing an infinite loop. The loop continues until the database
  11431.  becomes full.
  11432.  
  11433.  Column  Datatype   Description
  11434.  ────────────────────────────────────────────────────────────────────────────
  11435.  xactid  binary(6)  Transaction ID
  11436.  op      tinyint    Update operation number
  11437.  ────────────────────────────────────────────────────────────────────────────
  11438.  
  11439.  
  11440.  Indexes
  11441.  
  11442.  None
  11443.  
  11444.  
  11445.  sysmessages (master database only)
  11446.  
  11447.  
  11448.  Description
  11449.  
  11450.  Contains one row for each system error or warning that can be returned by
  11451.  SQL Server. SQL Server displays the error description on the user's screen.
  11452.  
  11453.  
  11454.  Column       Datatype      Description
  11455.  ────────────────────────────────────────────────────────────────────────────
  11456.  error        int           Unique error number
  11457.  
  11458.  severity     smallint      Severity level of error
  11459.  
  11460.  dlevel       smallint      Reserved for number of descriptive level of
  11461.                             this message:  terse, short, or long
  11462.  
  11463.  description  varchar(255)  Explanation of error with place holders for
  11464.                             parameters
  11465.  
  11466.  ────────────────────────────────────────────────────────────────────────────
  11467.  
  11468.  
  11469.  
  11470.  Indexes
  11471.  
  11472.  Unique clustered index on error and dlevel
  11473.  
  11474.  
  11475.  sysobjects (all databases)
  11476.  
  11477.  
  11478.  Description
  11479.  
  11480.  Contains one row for each table, view, stored procedure, log, rule, default,
  11481.  trigger, and (in tempdb only) temporary object.
  11482.  
  11483. ╓┌─────────┌─────────┌───────────────────────────────────────────────────────╖
  11484.  Column    Datatype  Description
  11485.  ────────────────────────────────────────────────────────────────────────────
  11486.  name      sysname   Object name
  11487.  
  11488.  id        int       Object ID
  11489.  Column    Datatype  Description
  11490.  ────────────────────────────────────────────────────────────────────────────
  11491. id        int       Object ID
  11492.  
  11493.  uid       smallint  User ID of owner object
  11494.  
  11495.  type      char      One of the following object types:
  11496.                      S System table
  11497.                      U User table
  11498.                      V View
  11499.                      L Log
  11500.                      P Stored procedure
  11501.                      R Rule
  11502.                      D Default
  11503.                      TR Trigger
  11504.  
  11505.  userstat  smallint  Application-dependent type information
  11506.  
  11507.  sysstat   smallint  Internal status information
  11508.  
  11509.  indexdel  smallint  Index delete count (incremented if an index is deleted)
  11510.  Column    Datatype  Description
  11511.  ────────────────────────────────────────────────────────────────────────────
  11512. indexdel  smallint  Index delete count (incremented if an index is deleted)
  11513.  
  11514.  schema    smallint  Count of changes in schema of a given object
  11515.                      (incremented if a rule or default is added)
  11516.  
  11517.  refdate   datetime  reserved
  11518.  
  11519.  crdate    datetime  Date object was created
  11520.  
  11521.  expdate   datetime  reserved
  11522.  
  11523.  deltrig   int       Stored procedure ID of a delete trigger
  11524.  
  11525.  instrig   int       Stored procedure ID of an insert trigger
  11526.  
  11527.  updtrig   int       Stored procedure ID of an update trigger
  11528.  
  11529.  seltrig   int       reserved
  11530.  
  11531.  Column    Datatype  Description
  11532.  ────────────────────────────────────────────────────────────────────────────
  11533. 
  11534.  category  int       reserved
  11535.  
  11536.  cache     smallint  reserved
  11537.  
  11538.  ────────────────────────────────────────────────────────────────────────────
  11539.  
  11540.  
  11541.  
  11542.  
  11543.  Indexes
  11544.  
  11545.  Unique clustered index on id Unique nonclustered index on name and uid
  11546.  
  11547.  
  11548.  Referenced by System Procedures
  11549.  
  11550.  sp_bindefault, sp_bindrule, sp_commonkey, sp_depends, sp_dropgroup,
  11551.  sp_dropkey, sp_droptype, sp_dropuser, sp_foreignkey, sp_help, sp_helpjoins,
  11552.  sp_helprotect, sp_primarykey, sp_rename, sp_unbindefault, sp_unbindrule
  11553.  
  11554.  
  11555.  sysprocedures (all databases)
  11556.  
  11557.  
  11558.  Description
  11559.  
  11560.  Contains entries for each view, default, rule, trigger, and stored
  11561.  procedure. The plan or sequence tree for each object is stored in binary
  11562.  form. If the sequence tree doesn't fit in one entry, it is broken into more
  11563.  than one row. The sequence field identifies the sub-rows.
  11564.  
  11565. ╓┌─────────┌─────────┌───────────────────────────────────────────────────────╖
  11566.  Column    Datatype  Description
  11567.  ────────────────────────────────────────────────────────────────────────────
  11568.  type      smallint  Object type:
  11569.                      0x1 Entry describes a plan (reserved)
  11570.                      0x2 Entry describes a tree
  11571.  
  11572.  id        int       Object ID
  11573.  Column    Datatype  Description
  11574.  ────────────────────────────────────────────────────────────────────────────
  11575. id        int       Object ID
  11576.  
  11577.  sequence  smallint  Sequence number if more than one row is used to
  11578.                      describe this object
  11579.  
  11580.  status    smallint  Internal system status
  11581.  
  11582.  number    smallint  Subprocedure number when the procedure is grouped (0
  11583.                      for nonprocedure entries)
  11584.  
  11585.  ────────────────────────────────────────────────────────────────────────────
  11586.  
  11587.  
  11588.  
  11589.  
  11590.  Indexes
  11591.  
  11592.  Unique clustered index on id, number, type, and sequence
  11593.  
  11594.  
  11595.  sysprocesses (master database only)
  11596.  
  11597.  
  11598.  Description
  11599.  
  11600.  Contains information about SQL Server processes. The sysprocesses system
  11601.  table is not a standard table. Rather, it is built dynamically when queried
  11602.  by a user. No updates to sysprocesses are allowed. Use the KILL statement to
  11603.  kill a process.
  11604.  
  11605. ╓┌─────────────┌─────────┌───────────────────────────────────────────────────╖
  11606.  Column        Datatype  Description
  11607.  ────────────────────────────────────────────────────────────────────────────
  11608.  spid          smallint  Process ID
  11609.  
  11610.  kpid          smallint  Kernel process ID
  11611.  
  11612.  status        char(10)  Process ID status (for example, runnable, sleeping,
  11613.                          and so on)
  11614.  
  11615.  Column        Datatype  Description
  11616.  ────────────────────────────────────────────────────────────────────────────
  11617. 
  11618.  suid          smallint  Server user ID of user who executed command
  11619.  
  11620.  hostname      char(10)  Name of workstation
  11621.  
  11622.  program_name  char(16)  Name of application program
  11623.  
  11624.  hostprocess   char(8)   Workstation process ID number
  11625.  
  11626.  cmd           char(16)  Command currently being executed
  11627.  
  11628.  cpu           int       Cumulative CPU time for process
  11629.  
  11630.  physical_io   int       Number of disk reads and writes for current
  11631.                          command
  11632.  
  11633.  memusage      int       Amount of memory allocated to process
  11634.  
  11635.  blocked       smallint  Process ID of blocking process, if any
  11636.  Column        Datatype  Description
  11637.  ────────────────────────────────────────────────────────────────────────────
  11638. blocked       smallint  Process ID of blocking process, if any
  11639.  
  11640.  dbid          smallint  Database ID
  11641.  
  11642.  uid           smallint  ID of user who executed command
  11643.  
  11644.  gid           smallint  Group ID of user who executed command
  11645.  
  11646.  ────────────────────────────────────────────────────────────────────────────
  11647.  
  11648.  
  11649.  
  11650.  
  11651.  Indexes
  11652.  
  11653.  None
  11654.  
  11655.  
  11656.  Referenced by System Procedures
  11657.  
  11658.  sp_who
  11659.  
  11660.  
  11661.  sysprotects (all databases)
  11662.  
  11663.  
  11664.  Description
  11665.  
  11666.  Contains user permissions information─entries for each GRANT and REVOKE
  11667.  statement that has been executed.
  11668.  
  11669. ╓┌────────────┌──────────────┌───────────────────────────────────────────────╖
  11670.  Column       Datatype       Description
  11671.  ────────────────────────────────────────────────────────────────────────────
  11672.  id           int            ID of object to which this permission applies
  11673.  
  11674.  uid          smallint       ID of user or group to which this permission
  11675.                              applies
  11676.  
  11677.  action       tinyint        One of the following permissions:
  11678.  Column       Datatype       Description
  11679.  ────────────────────────────────────────────────────────────────────────────
  11680. action       tinyint        One of the following permissions:
  11681.                              SELECT = 193
  11682.                              INSERT = 195
  11683.                              DELETE = 196
  11684.                              UPDATE = 197
  11685.                              EXECUTE = 224
  11686.                              CREATE DATABASE = 203
  11687.                              CREATE DEFAULT = 233
  11688.                              CREATE PROCEDURE = 222
  11689.                              CREATE RULE = 236
  11690.                              CREATE TABLE = 198
  11691.                              CREATE VIEW = 207
  11692.                              DUMP DATABASE = 228
  11693.                              DUMP TRANSACTION = 235
  11694.  
  11695.  protecttype  tinyint        Either 205 (grant) or 206 (revoke)
  11696.  
  11697.  columns      varbinary(32)  Bit map of columns to which this SELECT or
  11698.                              UPDATE permission applies. Bit 0 indicates all
  11699.  Column       Datatype       Description
  11700.  ────────────────────────────────────────────────────────────────────────────
  11701.                             UPDATE permission applies. Bit 0 indicates all
  11702.                              columns; bit 1 means permission applies to
  11703.                              that column; NULL means no information.
  11704.  
  11705.  ────────────────────────────────────────────────────────────────────────────
  11706.  
  11707.  
  11708.  
  11709.  
  11710.  Indexes
  11711.  
  11712.  Clustered index on id, uid, and action
  11713.  
  11714.  
  11715.  Referenced by System Procedures
  11716.  
  11717.  sp_helprotect
  11718.  
  11719.  
  11720.  syssegments (all databases)
  11721.  
  11722.  
  11723.  Description
  11724.  
  11725.  Contains one row for each segment (named collection of disk pieces). When
  11726.  SQL Server is installed, this table contains two entries: segment 0 (system)
  11727.  for system tables and segment 1 (default) for other objects. All entries in
  11728.  sysusages contain both these segments in their maps.
  11729.  
  11730.  Column   Datatype  Description
  11731.  ────────────────────────────────────────────────────────────────────────────
  11732.  segment  smallint  Segment number
  11733.  name     sysname   Segment name, used internally
  11734.  status   int null  Indicates which is the default segment
  11735.  ────────────────────────────────────────────────────────────────────────────
  11736.  
  11737.  
  11738.  Indexes
  11739.  
  11740.  None
  11741.  
  11742.  
  11743.  systypes (all databases)
  11744.  
  11745.  
  11746.  Description
  11747.  
  11748.  Contains one row for each system-supplied and each user-defined datatype.
  11749.  Domains (defined by rules) and defaults are given if they exist. The rows
  11750.  that describe system-supplied datatypes cannot be altered. The
  11751.  system-supplied datatypes and their ID numbers (the contents of the name and
  11752.  type fields, respectively) are as follows:
  11753.  
  11754. ╓┌───────────────────────────────┌───────────────────────────────────────────╖
  11755.  System Datatype                 ID Number
  11756.  ────────────────────────────────────────────────────────────────────────────
  11757.  binary                          45
  11758.  bit                             50
  11759.  char                            4
  11760.  datetime                        61
  11761.  datetimn                        111
  11762.  System Datatype                 ID Number
  11763.  ────────────────────────────────────────────────────────────────────────────
  11764. datetimn                        111
  11765.  float                           62
  11766.  floatn                          109
  11767.  image                           46
  11768.  int                             56
  11769.  intn                            38
  11770.  money                           60
  11771.  moneyn                          110
  11772.  smallint                        52
  11773.  sysname                         39
  11774.  text                            35
  11775.  timestamp                       37
  11776.  tinyint                         48
  11777.  varbinary                       37
  11778.  varchar                         39
  11779.  ────────────────────────────────────────────────────────────────────────────
  11780.  
  11781.  
  11782.  The following table shows the datatype and description for each column in
  11783.  the systypes table.
  11784.  
  11785. ╓┌───────────┌─────────────┌─────────────────────────────────────────────────╖
  11786.  Column      Datatype      Description
  11787.  ────────────────────────────────────────────────────────────────────────────
  11788.  uid         smallint      User ID of datatype creator
  11789.  
  11790.  usertype    smallint      User type ID
  11791.  
  11792.  variable    bit           1 if datatype is variable length; 0 otherwise
  11793.  
  11794.  allownulls  bit           Indicates whether NULLs are allowed for this
  11795.                            datatype
  11796.  
  11797.  type        tinyint       Physical storage datatype
  11798.  
  11799.  length      tinyint       Physical length of datatype
  11800.  
  11801.  tdefault    int           ID of stored procedure that generates default
  11802.                            for this datatype
  11803.  
  11804.  Column      Datatype      Description
  11805.  ────────────────────────────────────────────────────────────────────────────
  11806. 
  11807.  domain      int           ID of stored procedure that contains integrity
  11808.                            checks for this datatype
  11809.  
  11810.  name        sysname       Datatype name
  11811.  
  11812.  printfmt    varchar(255)  reserved
  11813.  
  11814.  ────────────────────────────────────────────────────────────────────────────
  11815.  
  11816.  
  11817.  
  11818.  
  11819.  Indexes
  11820.  
  11821.  Unique clustered index on name Unique nonclustered index on usertype
  11822.  
  11823.  
  11824.  Referenced by System Procedures
  11825.  
  11826.  sp_addtype, sp_bindefault, sp_bindrule, sp_droptype, sp_dropuser, sp_help,
  11827.  sp_rename, sp_unbindefault, sp_unbindrule
  11828.  
  11829.  
  11830.  sysusages (master database only)
  11831.  
  11832.  
  11833.  Description
  11834.  
  11835.  Contains one row for each disk allocation piece assigned to a database. Each
  11836.  database contains a specified number of database (logical) page numbers.
  11837.  Each disk piece includes segments 0 and 1.
  11838.  
  11839.  When the CREATE DATABASE statement is executed, SQL Server scans the disk(s)
  11840.  to find available disk allocation pieces. One or more contiguous disk
  11841.  allocation pieces is assigned to the database, and the mapping is recorded
  11842.  in sysusages.
  11843.  
  11844. ╓┌───────┌─────────┌─────────────────────────────────────────────────────────╖
  11845.  Column  Datatype  Description
  11846.  Column  Datatype  Description
  11847.  ────────────────────────────────────────────────────────────────────────────
  11848.  dbid    smallint  Database ID
  11849.  segmap  int       Bit map of possible segment assignments
  11850.  lstart  int       First database (logical) page number
  11851.  size    int       Number of contiguous database (logical) pages
  11852.  vstart  int       Starting virtual page number
  11853.  ────────────────────────────────────────────────────────────────────────────
  11854.  
  11855.  
  11856.  
  11857.  Indexes
  11858.  
  11859.  Unique clustered index on dbid and lstart Unique nonclustered index on
  11860.  vstart
  11861.  
  11862.  
  11863.  Referenced by System Procedures
  11864.  
  11865.  sp_logdevice
  11866.  
  11867.  
  11868.  sysusers (all databases)
  11869.  
  11870.  
  11871.  Description
  11872.  
  11873.  Contains one row for each user allowed in the database and one row for each
  11874.  group.
  11875.  
  11876.  On the SQL Server distribution diskette, master..sysusers contains three
  11877.  entries: dbo, whose suid is 1 and uid is 1; guest, whose suid is -1 and uid
  11878.  is 2; and public, whose suid is -2 and uid is 0. The sysusers table in the
  11879.  model database (and thus in all user databases) initially contains two
  11880.  entries: dbo and public.
  11881.  
  11882.  The user guest provides a mechanism for giving access to the database to
  11883.  users not explicitly listed in sysusers, with a restricted set of
  11884.  permissions. The guest entry in master means that any user with an account
  11885.  on SQL Server (that is, with an entry in syslogins) can access master.
  11886.  
  11887.  The user public refers to all users. The keyword PUBLIC is used with the
  11888.  GRANT and REVOKE statements to signify that the permission is being given to
  11889.  or taken away from all users.
  11890.  
  11891. ╓┌────────┌─────────────┌────────────────────────────────────────────────────╖
  11892.  Column   Datatype      Description
  11893.  ────────────────────────────────────────────────────────────────────────────
  11894.  uid      smallint      Server user ID, copied from syslogins. suid 1 is
  11895.                         the System Administrator; -1 is a guest account.
  11896.  
  11897.  uid      smallint      User ID, unique in this database, used for granting
  11898.                         and revoking permissions. uid 1 is the dbo.
  11899.  
  11900.  gid      smallint      Group ID to which this user belongs. If uid = gid,
  11901.                         this entry defines a group, and suid for this entry
  11902.                         is 0.
  11903.  
  11904.  name     sysname       Username or groupname, unique in this database.
  11905.  
  11906.  environ  varchar(255)  reserved
  11907.  
  11908.  ────────────────────────────────────────────────────────────────────────────
  11909.  Column   Datatype      Description
  11910.  ────────────────────────────────────────────────────────────────────────────
  11911. ────────────────────────────────────────────────────────────────────────────
  11912.  
  11913.  
  11914.  
  11915.  
  11916.  Indexes
  11917.  
  11918.  Unique clustered index on suid Unique nonclustered index on name Unique
  11919.  nonclustered index on uid
  11920.  
  11921.  
  11922.  Referenced by System Procedures
  11923.  
  11924.  sp_addalias, sp_adduser, sp_addgroup, sp_changedbowner, sp_changegroup,
  11925.  sp_dropgroup, sp_droplogin, sp_droptype, sp_dropuser, sp_helpgroup,
  11926.  sp_helprotect, sp_helpuser
  11927.  
  11928.  Figure B.1: System Tables Relationship Chart -
  11929.  
  11930.  (This figure may be found in the printed book.)
  11931.  
  11932.  
  11933.  
  11934.  
  11935.  
  11936.  
  11937.  Appendix C  Special Keys
  11938.  ────────────────────────────────────────────────────────────────────────────
  11939.  
  11940.   The following keys and key combinations have special functions when using
  11941.  the SAF:
  11942.  
  11943.  
  11944.  Editing Keys (Dialog Boxes)
  11945.  
  11946.  Function                                 Key
  11947.  ────────────────────────────────────────────────────────────────────────────
  11948.  Cancel current selection                 ESC
  11949.  Move cursor to next field                TAB
  11950.  Move cursor to previous field            SHIFT+TAB
  11951.  ────────────────────────────────────────────────────────────────────────────
  11952.  
  11953.  
  11954.  Editing Keys (SQL Windows)
  11955.  
  11956. ╓┌──────────────────────────────────────────┌────────────────────────────────╖
  11957.  Function                                   Key
  11958.  ────────────────────────────────────────────────────────────────────────────
  11959.  Delete character above cursor              DEL
  11960.  Delete character to left of cursor         BACKSPACE
  11961.  Delete line at cursor                      CTRL+D
  11962.  Move cursor to beginning of line           HOME
  11963.  Move cursor to end of line                 END
  11964.  Move cursor to top of screen               CTRL+HOME
  11965.  Move cursor to bottom of screen            CTRL+END
  11966.  Move down one line                         DOWN
  11967.  Move down one page                         PG DN
  11968.  Move left one character                    LEFT
  11969.  Move right one character                   RIGHT
  11970.  Move up one line                           UP
  11971.  Move up one page                           PG UP
  11972.  Function                                   Key
  11973.  ────────────────────────────────────────────────────────────────────────────
  11974. Move up one page                           PG UP
  11975.  Select character to left of cursor         SHIFT+LEFT
  11976.  Select character to right of cursor        SHIFT+RIGHT
  11977.  Select next line                           SHIFT+DOWN
  11978.  Select previous line                       SHIFT+UP
  11979.  Select word to left of cursor              SHIFT+CTRL+LEFT
  11980.  Select word to right of cursor             SHIFT+CTRL+RIGHT
  11981.  Switch between insert and overtype         CTRL+O
  11982.  Exit SAF                                   F3
  11983.  Get Help                                   F1
  11984.  ────────────────────────────────────────────────────────────────────────────
  11985.  
  11986.  
  11987.  
  11988.  Menu Keys
  11989.  
  11990. ╓┌────────────────────────────────────────────┌──────────────────────────────╖
  11991.  Function                                     Key
  11992.  ────────────────────────────────────────────────────────────────────────────
  11993.  Function                                     Key
  11994.  ────────────────────────────────────────────────────────────────────────────
  11995.  Access Admin menu                            ALT+A
  11996.  Access Config menu                           ALT+C
  11997.  Access File menu                             ALT+F
  11998.  Access Query menu                            ALT+Q
  11999.  Access Window menu                           ALT+W
  12000.  Cancel current operation                     ESC
  12001.  Choose highlighted command button            ENTER
  12002.  Highlight first letter of menus              ALT
  12003.  ────────────────────────────────────────────────────────────────────────────
  12004.  
  12005.  
  12006.  
  12007.  Query Keys
  12008.  
  12009. ╓┌────────────────────────────────────────────────┌──────────────────────────╖
  12010.  Function                                         Key
  12011.  ────────────────────────────────────────────────────────────────────────────
  12012.  Clear window                                     CTRL+N
  12013.  Execute query                                    CTRL+E
  12014.  Function                                         Key
  12015.  ────────────────────────────────────────────────────────────────────────────
  12016. Execute query                                    CTRL+E
  12017.  SQL Query Window                                 CTRL+Q
  12018.  SQL Results Window                               CTRL+R
  12019.  SQL Results Full Window                          CTRL+F
  12020.  Switch from one window to another                F6
  12021.  Switch between Query and Results windows         CTRL+W
  12022.  ────────────────────────────────────────────────────────────────────────────
  12023.  
  12024.  
  12025.  
  12026.  
  12027.  
  12028.  INDEX
  12029.  ──────────────────────────────────────────────────────────────────────────
  12030.  
  12031.  
  12032.  
  12033.  
  12034.      A
  12035.  Accelerator keys
  12036.  Access to database
  12037.    restrict using stored procedure
  12038.    restrict using view
  12039.  Add a Groupname dialog box
  12040.  Add a Login ID dialog box
  12041.  Add a Username dialog box
  12042.  Add alias
  12043.    Admin menu
  12044.    SQL Query Window
  12045.  Add group
  12046.    Admin menu
  12047.    SQL Query Window
  12048.  Add login ID
  12049.    Admin menu
  12050.  Add password
  12051.    Admin menu
  12052.    SQL Query Window
  12053.  Add username
  12054.    Admin menu
  12055.    SQL Query Window
  12056.  Admin menu
  12057.    add group
  12058.    add login ID
  12059.    add password
  12060.    add username
  12061.    assign default database
  12062.    change Database Owner
  12063.    change group
  12064.    change password
  12065.    create alias
  12066.    delete group
  12067.    delete login ID
  12068.    delete username
  12069.    display current users
  12070.    dump database
  12071.    dump transaction log
  12072.    load database
  12073.    load transaction log
  12074.    manage aliases
  12075.    manage groups
  12076.    manage login IDs
  12077.    manage usernames
  12078.    remove alias
  12079.    truncate transaction log
  12080.  Alias
  12081.    create using Admin menu
  12082.    create using SQL Query Window
  12083.    defined
  12084.    display information on
  12085.    manage
  12086.    remove using Admin menu
  12087.    remove using SQL Query Window
  12088.  Allocate space for database
  12089.  Allocation page
  12090.  Allow updates configuration option
  12091.  ALT key
  12092.  ALT+A key
  12093.  ALT+C key
  12094.  ALT+F key
  12095.  ALT+Q key
  12096.  ALT+W key
  12097.  ALTER DATABASE statement
  12098.  ASCII format for data transfer
  12099.  Assign default database
  12100.    Admin menu
  12101.  Associated username list box
  12102.  authors table
  12103.  
  12104.      B
  12105.  BACKSPACE key
  12106.  Backup (Dump) Database dialog box
  12107.  Backup menu item
  12108.  Backup
  12109.    database
  12110.    files for
  12111.    master database
  12112.    permissions
  12113.    transaction log
  12114.  Batch file
  12115.  bcp utility program
  12116.    change defaults interactively
  12117.    option, character
  12118.    option, native
  12119.    syntax
  12120.  Binary format for data transfer
  12121.  bldmastr utility program
  12122.  Box
  12123.    dialog
  12124.    list
  12125.    text
  12126.  Bulk copy utility
  12127.    transfer data using
  12128.  Button
  12129.    command
  12130.    option
  12131.  
  12132.      C
  12133.  Cache
  12134.    data
  12135.    procedure
  12136.  Cancel command button
  12137.  Chain, ownership
  12138.  Change Database Owner dialog box
  12139.  Change database owner menu item
  12140.  Change Database Owner
  12141.    Admin menu
  12142.    SQL Query Window
  12143.  Change default database
  12144.    SQL Query Window
  12145.  Change Group dialog box
  12146.  Change group
  12147.    Admin menu
  12148.    SQL Query Window
  12149.  Change password
  12150.    Admin menu
  12151.    SQL Query Window
  12152.  Change User Password dialog box
  12153.  Character
  12154.    bcp option
  12155.    data format
  12156.  CHECKALLOC option of DBCC
  12157.  CHECKCATALOG option of DBCC
  12158.  CHECKDB option of DBCC
  12159.  CHECKPOINT statement
  12160.    with rollback transaction
  12161.  Checkpoint
  12162.  CHECKTABLE option of DBCC
  12163.  Clauses
  12164.    GROUP BY
  12165.    ORDER BY
  12166.  Column, separator
  12167.  Command button
  12168.    Cancel
  12169.    OK
  12170.    select with mouse
  12171.    select
  12172.  Common key
  12173.  Config menu
  12174.    change configuration options
  12175.    display configuration option settings
  12176.    shut down SQL Server
  12177.  Configuration options
  12178.    allow updates
  12179.    change using Config menu
  12180.    change using SQL Query Window
  12181.    database size
  12182.    display settings using Config menu
  12183.    display settings
  12184.    dynamic
  12185.    fill factor
  12186.    general
  12187.    locks
  12188.    media retention
  12189.    memory
  12190.    open databases
  12191.    open objects
  12192.    procedure cache
  12193.    recovery flags
  12194.    recovery interval
  12195.    serial number
  12196.    time slice
  12197.    user connections
  12198.  Connections
  12199.    required by system
  12200.    required by users
  12201.  console utility program
  12202.  Controller number
  12203.  Copy data
  12204.    for use by other programs
  12205.    from file to database table
  12206.    to file
  12207.  Create alias
  12208.    Admin menu
  12209.    SQL Query Window
  12210.  Create an Alias dialog box
  12211.  CREATE DATABASE statement
  12212.  CREATE PROCEDURE statement
  12213.  CREATE VIEW statement
  12214.  CTRL+D key
  12215.  CTRL+E key
  12216.  CTRL+END key
  12217.  CTRL+F key
  12218.  CTRL+HOME key
  12219.  CTRL+N key
  12220.  CTRL+O key
  12221.  CTRL+Q key
  12222.  CTRL+R key
  12223.  CTRL+W key
  12224.  
  12225.      D
  12226.  Data cache
  12227.  Data format for copying
  12228.    character
  12229.    native
  12230.  Data transfer (bcp program)
  12231.    compact storage
  12232.    copy for use by other programs
  12233.    copy from file to database table
  12234.    copy to file
  12235.    copy using bulk copy utility
  12236.    integrity when transferring
  12237.    modify data for transfer
  12238.    store
  12239.  Data transfer, indexes
  12240.  Database device
  12241.    add
  12242.    display information on
  12243.    drop
  12244.    logical name
  12245.    physical name
  12246.    remove
  12247.    set default
  12248.  Database name list box
  12249.  Database object owner
  12250.    defined
  12251.    login ID
  12252.    password
  12253.    permissions
  12254.  Database object
  12255.    default
  12256.    defined
  12257.    index
  12258.    rule
  12259.    stored procedure
  12260.    table
  12261.    temporary
  12262.    trigger
  12263.    view
  12264.  Database options
  12265.    change
  12266.    dbo use only
  12267.    display information
  12268.    no chkpt on recovery
  12269.    read only
  12270.    select into/bulkcopy
  12271.    set
  12272.    single user
  12273.    trunc. log on chkpt.
  12274.  Database Owner
  12275.    change using Admin menu
  12276.    change using SQL Query Window
  12277.    defined
  12278.    display information on
  12279.    login ID
  12280.    password
  12281.    permissions
  12282.    System Administrator as
  12283.  Database size configuration
  12284.  Database, sample
  12285.  Database
  12286.    allocate space
  12287.    alter size
  12288.    assign default using Admin menu
  12289.    back up
  12290.    build master
  12291.    change default using SQL Query Window
  12292.    changes to master
  12293.    context-sensitive permissions
  12294.    default
  12295.    delete
  12296.    display information on storage
  12297.    drop
  12298.    dump master
  12299.    dump using Admin menu
  12300.    dump using SQL Query Window
  12301.    dump
  12302.    interaction with transaction log
  12303.    list box
  12304.    load using Admin menu
  12305.    load using SQL Query Window
  12306.    load
  12307.    location
  12308.    manage groups
  12309.    manage usernames
  12310.    master
  12311.    model
  12312.    monitor size
  12313.    move
  12314.    name
  12315.    permission to access
  12316.    pubs
  12317.    recover damaged master
  12318.    reload master
  12319.    restrict access using stored procedure
  12320.    restrict access using view
  12321.    sample
  12322.    size
  12323.    system
  12324.    temporary
  12325.    what to do if out of space
  12326.    when to dump
  12327.  DB-LIBRARY
  12328.    function
  12329.    two-phase commit service
  12330.  DBCC CHECKALLOC statement
  12331.  DBCC options
  12332.    CHECKALLOC
  12333.    CHECKCATALOG
  12334.    CHECKDB
  12335.    CHECKTABLE
  12336.    DBREPAIR
  12337.  DBCC statement
  12338.  dbo use only database option
  12339.  dbo username
  12340.  DBREPAIR option of DBCC
  12341.  Deadlock
  12342.  Default database text box
  12343.  defncopy utility program
  12344.  DEL key
  12345.  Delete alias
  12346.    Admin menu
  12347.    SQL Query Window
  12348.  Delete group
  12349.    Admin menu
  12350.    SQL Query Window
  12351.  Delete login ID
  12352.    Admin menu
  12353.    SQL Query Window
  12354.  Delete username
  12355.    Admin menu
  12356.    SQL Query Window
  12357.  Demand lock
  12358.  Descriptor, file
  12359.  Device, dump
  12360.  Dialog box
  12361.    Add a Groupname
  12362.    Add a Login ID
  12363.    Add a Username
  12364.    areas in
  12365.    Backup (Dump) Database
  12366.    Change Database Owner
  12367.    Change Group
  12368.    Change User Password
  12369.    clear from screen
  12370.    Create an Alias
  12371.    Groupname
  12372.    Login to SQL Server
  12373.    Manage Groups
  12374.    Manage Login IDs
  12375.    Manage Usernames
  12376.    move cursor within
  12377.    Restore (Load) Database
  12378.    Start a Server
  12379.  Direction keys
  12380.  discounts table
  12381.  Disk dump device
  12382.  DISK INIT statement
  12383.  DISK REFIT statement
  12384.  DISK REINIT statement
  12385.  Diskette
  12386.    dump device
  12387.    storage capacity
  12388.  Display current users menu item
  12389.  Display field
  12390.    defined
  12391.  DOWN key
  12392.  DROP DATABASE statement
  12393.  Drop
  12394.    alias
  12395.    database device
  12396.    dump device
  12397.  DUMP DATABASE statement
  12398.  Dump database
  12399.    Admin menu
  12400.    interaction with transaction log
  12401.    SQL Query Window
  12402.  Dump device list box
  12403.  Dump device
  12404.    add
  12405.    controller number
  12406.    defined
  12407.    disk
  12408.    diskette
  12409.    display information on
  12410.    drop
  12411.    logical name
  12412.    null
  12413.    remove
  12414.    storage capacity
  12415.  Dump transaction log
  12416.    Admin menu
  12417.    advantage of
  12418.    interaction with database
  12419.    SQL Query Window
  12420.  DUMP TRANSACTION statement
  12421.  Dump
  12422.    database using SQL Query Window
  12423.    database
  12424.    master database
  12425.    transaction log using Admin menu
  12426.    transaction log using SQL Query Window
  12427.    transaction log
  12428.    when to perform
  12429.  
  12430.      E
  12431.  Editing keys
  12432.  END key
  12433.  ENTER key
  12434.  Error
  12435.    fatal
  12436.    file
  12437.    log
  12438.    message number
  12439.    message
  12440.    report
  12441.    severity level
  12442.    system
  12443.    user correctable
  12444.    user
  12445.  ESC key
  12446.  Exclusive lock
  12447.  Extent lock
  12448.  
  12449.      F
  12450.  F1 key
  12451.  F3 key
  12452.  F6 key
  12453.  Field terminator
  12454.  Field, display
  12455.  File menu
  12456.  File
  12457.    backup
  12458.    descriptor
  12459.    error
  12460.    storage type
  12461.  Fill factor configuration option
  12462.  Foreign key
  12463.  Function keys
  12464.    F3
  12465.    F6
  12466.  
  12467.      G
  12468.  Global variables
  12469.  
  12470.      @@MAX_CONNECTIONS
  12471.      @@NESTLEVEL
  12472.      @@PROCID
  12473.      @@ROWCOUNT
  12474.      @@TEXTSIZE
  12475.      @@TIMETICKS
  12476.      @@TRANCOUNT
  12477.      @@VERSION
  12478.    query
  12479.  GRANT statement
  12480.    combine permissions
  12481.    conflicting permissions
  12482.  Grant
  12483.    object permissions
  12484.    statement permissions
  12485.  GROUP BY clause
  12486.  Group
  12487.    add using Admin menu
  12488.    add using SQL Query Window
  12489.    change using Admin menu
  12490.    change using SQL Query Window
  12491.    defined
  12492.    delete using Admin menu
  12493.    delete using SQL Query Window
  12494.    display information on
  12495.    manage using Admin menu
  12496.    manage using SQL Query Window
  12497.    public
  12498.    set up
  12499.  Groupname text box
  12500.  Groupname
  12501.    assign
  12502.    dialog box
  12503.    public
  12504.  Guest
  12505.    account
  12506.    user permissions
  12507.    user
  12508.  
  12509.      H
  12510.  Help menu
  12511.  Hierarchy, permissions
  12512.  HOLDLOCK keyword
  12513.  HOME key
  12514.  
  12515.      I
  12516.  Index
  12517.    and data transfer
  12518.    database object
  12519.  INSERT statement
  12520.  Integrity, referential
  12521.  Intent lock
  12522.  isql utility program
  12523.  
  12524.      K
  12525.  Keys
  12526.    accelerator
  12527.    ALT
  12528.    ALT+A
  12529.    ALT+C
  12530.    ALT+F
  12531.    ALT+Q
  12532.    ALT+W
  12533.    BACKSPACE
  12534.    common
  12535.    CTRL+D
  12536.    CTRL+E
  12537.    CTRL+END
  12538.    CTRL+F
  12539.    CTRL+HOME
  12540.    CTRL+N
  12541.    CTRL+O
  12542.    CTRL+Q
  12543.    CTRL+R
  12544.    CTRL+W key
  12545.    CTRL+W
  12546.    DEL
  12547.    direction
  12548.    DOWN
  12549.    editing keys
  12550.    END
  12551.    ENTER
  12552.    ESC
  12553.    F1
  12554.    F3
  12555.    F6
  12556.    foreign
  12557.    HOME
  12558.    LEFT
  12559.    menu keys
  12560.    PG DN
  12561.    PG UP
  12562.    primary
  12563.    query keys
  12564.    RIGHT
  12565.    SHIFT+CTRL+LEFT
  12566.    SHIFT+CTRL+RIGHT
  12567.    SHIFT+DOWN
  12568.    SHIFT+LEFT
  12569.    SHIFT+RIGHT
  12570.    SHIFT+TAB
  12571.    SHIFT+UP
  12572.    special
  12573.    system tables
  12574.    TAB
  12575.    UP
  12576.  Keywords
  12577.    HOLDLOCK
  12578.    PUBLIC
  12579.  KILL statement
  12580.  
  12581.      L
  12582.  LEFT key
  12583.  Length, storage
  12584.  List box
  12585.    Associated username
  12586.    Database name
  12587.    Database
  12588.    definition
  12589.    Dump device
  12590.    Load device
  12591.    Login ID
  12592.    New database owner
  12593.    New usergroup
  12594.    select item with mouse
  12595.    select item
  12596.    Server names
  12597.    User login ID/alias username
  12598.  Livelock
  12599.  LOAD DATABASE statement
  12600.  Load database
  12601.    Admin menu
  12602.    SQL Query Window
  12603.  Load device list box
  12604.  Load transaction log
  12605.    Admin menu
  12606.    SQL Query Window
  12607.  LOAD TRANSACTION statement
  12608.  Location of database
  12609.  Lock
  12610.    deadlock
  12611.    demand
  12612.    display information on
  12613.    exclusive
  12614.    extent
  12615.    intent
  12616.    livelock
  12617.    shared
  12618.  Locks configuration option
  12619.  Log, error
  12620.  Log
  12621.    in to another server
  12622.    queries and results
  12623.  Logical name, dump device
  12624.  Login ID list box
  12625.  Login ID text box
  12626.  Login ID
  12627.    add using Admin menu
  12628.    assign
  12629.    Database object owner
  12630.    Database Owner
  12631.    delete using Admin menu
  12632.    delete using SQL Query Window
  12633.    display information on
  12634.    manage using Admin menu
  12635.    probe
  12636.    sa
  12637.    System Administrator
  12638.    visitor
  12639.  Login to SQL Server dialog box
  12640.  
  12641.      M
  12642.  Manage aliases menu item
  12643.  Manage Groups dialog box
  12644.  Manage Login IDs dialog box
  12645.  Manage login IDs menu item
  12646.  Manage Usernames dialog box
  12647.  Manage usernames menu item
  12648.  master database
  12649.    as default
  12650.    build
  12651.    changes
  12652.    dump
  12653.    recover damaged
  12654.    reload
  12655.    set permissions in
  12656.    System Administrator as owner
  12657.    when to dump
  12658.  Media failure
  12659.    recovery
  12660.  Media retention configuration option
  12661.  Memory configuration option
  12662.  Menu item
  12663.    Backup
  12664.    Change database owner
  12665.    choose
  12666.    Display current users
  12667.    Manage aliases
  12668.    Manage login IDs
  12669.    Manage usernames
  12670.    select with mouse
  12671.    Shutdown SQL Server
  12672.  Menu, Admin
  12673.    add group
  12674.    add login ID
  12675.    add password
  12676.    add username
  12677.    change Database Owner
  12678.    change group
  12679.    change password
  12680.    create alias
  12681.    delete group
  12682.    delete login ID
  12683.    delete username
  12684.    display current users
  12685.    dump database
  12686.    dump transaction log
  12687.    load database
  12688.    load transaction log
  12689.    manage aliases
  12690.    manage groups
  12691.    manage login IDs
  12692.    manage usernames
  12693.    remove alias
  12694.    truncate transaction log
  12695.  Menu, Config
  12696.    change configuration options
  12697.    display configuration option settings
  12698.    shut down SQL Server
  12699.  Menus
  12700.  Menus, SAF
  12701.  Menus
  12702.    Admin
  12703.    Config
  12704.    File
  12705.    Help
  12706.    permissions
  12707.    Query
  12708.    Window
  12709.  model database
  12710.    permissions
  12711.  Modify data for transfer
  12712.  Modify
  12713.    query
  12714.    results
  12715.  Mouse
  12716.    scroll with
  12717.    select command button with
  12718.    select option button with
  12719.    select text with
  12720.    using in list box
  12721.  Move
  12722.    data
  12723.    database
  12724.  
  12725.      N
  12726.  Name
  12727.    database
  12728.    logical for dump device
  12729.    logical
  12730.    physical
  12731.  Names for query and results files
  12732.  Native
  12733.    bcp option
  12734.    data format
  12735.  net command
  12736.    shut down SQL Server
  12737.    start SQL Server
  12738.  New database owner list box
  12739.  New usergroup list box
  12740.  no chkpt on recovery database option
  12741.  Notational conventions
  12742.  Null device
  12743.  Number
  12744.    controller
  12745.  
  12746.      O
  12747.  Object permissions
  12748.    grant
  12749.    revoke
  12750.  OK command button
  12751.  ON DEFAULT clause
  12752.  Open databases configuration option
  12753.  Open objects configuration option
  12754.  Option button
  12755.    select with mouse
  12756.    select
  12757.  Option
  12758.    change configuration using Config menu
  12759.    change configuration using SQL Query Window
  12760.    configuration
  12761.    database
  12762.    query
  12763.    SET statement
  12764.  ORDER BY clause
  12765.  Ownership chain
  12766.  
  12767.      P
  12768.  Password text box
  12769.  Password
  12770.    add using Admin menu
  12771.    add using SQL Query Window
  12772.    assign
  12773.    change using Admin menu
  12774.    change using SQL Query Window
  12775.    Database object owner
  12776.    Database Owner
  12777.    NULL
  12778.    System Administrator
  12779.  Permission
  12780.    for menu items
  12781.  Permissions
  12782.    access database
  12783.    ALTER DATABASE
  12784.    backup
  12785.    CHECKPOINT
  12786.    combine
  12787.    conflicting
  12788.    context-sensitive
  12789.    CREATE DATABASE
  12790.    database groups
  12791.    Database object owner
  12792.    Database Owner
  12793.    display information on
  12794.    guest
  12795.    hierarchy
  12796.    model database
  12797.    object
  12798.    public group
  12799.    RECONFIGURE
  12800.    SA
  12801.    select
  12802.    set in master database
  12803.    statement
  12804.    stored procedures
  12805.    summary table
  12806.    System Administrator
  12807.    system procedures
  12808.    system table
  12809.    to copy data from operating system file
  12810.    to copy data
  12811.    UPDATE STATISTICS
  12812.    use alias to assume
  12813.    views
  12814.  PG DN key
  12815.  PG UP key
  12816.  Primary key
  12817.  Print query and results
  12818.  probe login ID
  12819.  Procedure cache configuration option
  12820.  Process, stop
  12821.  Public group
  12822.  public groupname
  12823.  PUBLIC keyword
  12824.  publishers table
  12825.  pubs sample database
  12826.  
  12827.      Q
  12828.  Query keys
  12829.  Query
  12830.    create
  12831.    defined
  12832.    enter
  12833.    execute
  12834.    log to file
  12835.    log
  12836.    menu
  12837.    modify
  12838.    new
  12839.    print
  12840.    retrieve
  12841.    save
  12842.    set options
  12843.    system table
  12844.    view on separate screen
  12845.  
  12846.      R
  12847.  read only database option
  12848.  RECONFIGURE statement
  12849.  Record, query and results
  12850.  Recovery flags configuration option
  12851.  Recovery interval configuration option
  12852.  Referential integrity
  12853.  Remove alias
  12854.    Admin menu
  12855.    SQL Query Window
  12856.  Remove
  12857.    database device
  12858.    dump device
  12859.  Resources, allocate
  12860.  Restore (Load) Database dialog box
  12861.  Restore master database
  12862.  Results
  12863.    defined
  12864.    log to file
  12865.    modify
  12866.    print
  12867.    retrieve
  12868.    save
  12869.    view on separate screen
  12870.  REVOKE statement
  12871.    combine permissions
  12872.    conflicting permissions
  12873.  Revoke
  12874.    object permissions
  12875.    statement permissions
  12876.  RIGHT key
  12877.  ROLLBACK TRANSACTION statement
  12878.    with checkpoint
  12879.  roysched table
  12880.  Rule, database object
  12881.  
  12882.      S
  12883.  sa login ID
  12884.  SAF
  12885.    exit
  12886.    start
  12887.    use for queries and results
  12888.  sales table
  12889.  Sample database
  12890.  Sample database, pubs
  12891.  Save, query and results
  12892.  Scroll
  12893.    bar
  12894.    box
  12895.    with keys
  12896.    with mouse
  12897.  Security mechanism
  12898.    stored procedure as
  12899.    view as
  12900.  select into/bulkcopy database option
  12901.  SELECT statement
  12902.  Serial number configuration option
  12903.  Server names list box
  12904.  Server
  12905.    log in to
  12906.  SET statement
  12907.    inside trigger or stored procedure
  12908.    options
  12909.  setup program
  12910.  SETUSER statement
  12911.  Shared lock
  12912.  SHIFT+CTRL+LEFT key
  12913.  SHIFT+CTRL+RIGHT key
  12914.  SHIFT+DOWN key
  12915.  SHIFT+LEFT key
  12916.  SHIFT+RIGHT key
  12917.  SHIFT+TAB key
  12918.  SHIFT+UP key
  12919.  Shut down SQL Server
  12920.    Config menu
  12921.    net command
  12922.    SHUTDOWN statement
  12923.  Shutdown SQL Server menu item
  12924.  SHUTDOWN statement
  12925.    shut down SQL Server
  12926.  single user database option
  12927.  Single-user mode
  12928.  Space, database
  12929.  Special users
  12930.  sp_addalias
  12931.  sp_addgroup
  12932.  sp_addumpdevice
  12933.  sp_adduser
  12934.  sp_bindefault
  12935.  sp_changedbowner
  12936.  sp_changegroup
  12937.  sp_configure
  12938.  sp_dboption
  12939.  sp_defaultdb
  12940.  sp_diskdefault
  12941.  sp_dropalias
  12942.  sp_dropdevice
  12943.  sp_dropgroup
  12944.  sp_droplogin
  12945.  sp_dropuser
  12946.  sp_help
  12947.  sp_helpdb
  12948.  sp_helpdevice
  12949.  sp_helpgroup
  12950.  sp_helpindex
  12951.  sp_helpjoins
  12952.  sp_helpkey
  12953.  sp_helprotect
  12954.  sp_helpuser
  12955.  sp_lock
  12956.  sp_logdevice
  12957.  sp_monitor
  12958.  sp_password
  12959.  sp_spaceused
  12960.  sp_who
  12961.  SQL Query Window
  12962.  SQL Query window
  12963.  SQL Query Window
  12964.    add group
  12965.    add password
  12966.    add username
  12967.    change configuration options
  12968.    change Database Owner
  12969.    change default database
  12970.    change group
  12971.    change password
  12972.    create alias
  12973.    delete group
  12974.    delete login ID
  12975.    delete username
  12976.    display current users
  12977.    dump database
  12978.    dump transaction log
  12979.    load database
  12980.    manage groups
  12981.    remove alias
  12982.    truncate transaction log
  12983.  SQL Results Full window
  12984.  SQL Results window
  12985.  SQL Server Administration Facility (SAF)
  12986.    start SQL Server
  12987.  SQL Server
  12988.    database space
  12989.    default decisions
  12990.    monitor activity of
  12991.    shut down using Config menu
  12992.    shut down using net command
  12993.    shut down using SHUTDOWN statement
  12994.    start in single-user mode
  12995.    start using net command
  12996.    start using SAF
  12997.    tools for managing
  12998.  sqlservr utility program
  12999.  Start a Server dialog box
  13000.  Start SQL Server
  13001.    net command
  13002.    SAF
  13003.  Statement permissions
  13004.    grant
  13005.    revoke
  13006.    syntax
  13007.  Statements
  13008.    ALTER DATABASE
  13009.    CHECKPOINT
  13010.    CREATE DATABASE
  13011.    CREATE PROCEDURE
  13012.    CREATE VIEW
  13013.    DBCC CHECKALLOC
  13014.    DBCC
  13015.    DISK INIT
  13016.    DISK REFIT
  13017.    DISK REINIT
  13018.    DROP DATABASE
  13019.    DUMP DATABASE
  13020.    DUMP TRANSACTION
  13021.    GRANT
  13022.    KILL
  13023.    LOAD DATABASE
  13024.    LOAD TRANSACTION
  13025.    RECONFIGURE
  13026.    REVOKE
  13027.    SELECT
  13028.    SETUSER
  13029.    TRANSACT-SQL
  13030.    UPDATE STATISTICS
  13031.    USE
  13032.  Statistics, update
  13033.  Stop process
  13034.  Storage
  13035.    length
  13036.    manage
  13037.  Stored procedure
  13038.    as security mechanism
  13039.    database object
  13040.    permissions
  13041.    SET statement in
  13042.    trigger
  13043.  stores table
  13044.  Syntax
  13045.    ALTER DATABASE
  13046.    bcp
  13047.    CHECKPOINT
  13048.    CREATE DATABASE
  13049.    DBCC
  13050.    DISK INIT
  13051.    DROP DATABASE
  13052.    DUMP DATABASE
  13053.    DUMP TRANSACTION
  13054.    GRANT
  13055.    KILL
  13056.    LOAD DATABASE
  13057.    LOAD TRANSACTION
  13058.    object permissions
  13059.    REVOKE
  13060.    SET
  13061.    SETUSER
  13062.    sp_addalias
  13063.    sp_addgroup
  13064.    sp_addumpdevice
  13065.    sp_adduser
  13066.    sp_changedbowner
  13067.    sp_changegroup
  13068.    sp_configure
  13069.    sp_dboption
  13070.    sp_defaultdb
  13071.    sp_diskdefault
  13072.    sp_dropalias
  13073.    sp_dropdevice
  13074.    sp_dropgroup
  13075.    sp_droplogin
  13076.    sp_dropuser
  13077.    sp_helpgroup
  13078.    sp_helprotect
  13079.    sp_helpuser
  13080.    sp_logdevice
  13081.    sp_password
  13082.    statement permissions
  13083.    UPDATE STATISTICS
  13084.  sysalternates
  13085.  syscolumns
  13086.  syscomments
  13087.  sysconfigures
  13088.  syscurconfigs
  13089.  sysdatabases
  13090.  sysdepends
  13091.  sysdevices
  13092.  sysindexes
  13093.  syskeys
  13094.  syslocks
  13095.  syslogins
  13096.  syslogs
  13097.  sysmessages
  13098.  sysobjects
  13099.  sysprocedures
  13100.  sysprocesses system
  13101.  sysprocesses
  13102.  sysprotects
  13103.  syssegments
  13104.  System Administrator (SA)
  13105.    defined
  13106.    login ID
  13107.    password
  13108.    permissions
  13109.    responsibilities
  13110.  System database
  13111.  System function, user_id
  13112.  System problems, diagnose
  13113.  System procedures
  13114.    permissions
  13115.    sp_addalias
  13116.    sp_addgroup
  13117.    sp_addumpdevice
  13118.    sp_adduser
  13119.    sp_bindefault
  13120.    sp_changedbowner
  13121.    sp_changegroup
  13122.    sp_configure
  13123.    sp_dboption
  13124.    sp_defaultdb
  13125.    sp_diskdefault
  13126.    sp_dropalias
  13127.    sp_dropdevice
  13128.    sp_dropgroup
  13129.    sp_droplogin
  13130.    sp_dropuser
  13131.    sp_help
  13132.    sp_helpdb
  13133.    sp_helpdevice
  13134.    sp_helpgroup
  13135.    sp_helpindex
  13136.    sp_helpjoins
  13137.    sp_helpkey
  13138.    sp_helprotect
  13139.    sp_helpuser
  13140.    sp_lock
  13141.    sp_logdevice
  13142.    sp_monitor
  13143.    sp_password
  13144.    sp_spaceused
  13145.    sp_who
  13146.  System tables
  13147.    keys in
  13148.    list
  13149.    permissions
  13150.    query
  13151.    relationship chart
  13152.    syscolumns
  13153.    syscomments
  13154.    sysconfigures
  13155.    syscurconfigs
  13156.    sysdatabases
  13157.    sysdepends
  13158.    sysdevices
  13159.    sysindexes
  13160.    syskeys
  13161.    syslaternates
  13162.    syslocks
  13163.    syslogins
  13164.    syslogs
  13165.    sysmessages
  13166.    sysobjects
  13167.    sysprocedures
  13168.    sysprocesses
  13169.    sysprotects
  13170.    syssegments
  13171.    systypes
  13172.    sysusages
  13173.    sysusers
  13174.  systypes
  13175.  sysusages system table
  13176.  sysusages
  13177.  sysusers system table
  13178.  sysusers
  13179.  
  13180.      T
  13181.  TAB key
  13182.  Table
  13183.    copy data into
  13184.    database object
  13185.    structure
  13186.    temporary
  13187.  tempdb database
  13188.  Temporary database object
  13189.  Temporary database
  13190.  Temporary table
  13191.  Terminator
  13192.    change for character data format
  13193.    field
  13194.  Text box
  13195.    change information in
  13196.    Default database
  13197.    defined
  13198.    enter information in
  13199.    Groupname
  13200.    Login ID
  13201.    move cursor to
  13202.    Password
  13203.    use a mouse in
  13204.    use keys to move cursor
  13205.    Username in database
  13206.  Text
  13207.    delete
  13208.    scroll
  13209.    select with mouse
  13210.    select
  13211.  Time slice configuration options
  13212.  titleauthor table
  13213.  titles table
  13214.  TRANSACT-SQL
  13215.    statements
  13216.  Transaction log
  13217.    advantage of dumping separately
  13218.    back up
  13219.    defined
  13220.    dump using Admin menu
  13221.    dump using SQL Query Window
  13222.    dump
  13223.    expand space for
  13224.    interaction with database
  13225.    keep small
  13226.    load using Admin menu
  13227.    load
  13228.    put on different database device
  13229.    truncate using Admin menu
  13230.    truncate using SQL Query Window
  13231.    truncate
  13232.  Transfer data (bcp)
  13233.    for use by other programs
  13234.    in ASCII format
  13235.    in binary format
  13236.    information required
  13237.    using bulk copy utility
  13238.    with indexes
  13239.  Trigger
  13240.    database object
  13241.    SET statement in
  13242.  trunc. log on chkpt. database option
  13243.  Truncate transaction log
  13244.    Admin menu
  13245.    SQL Query Window
  13246.  Two-phase commit service
  13247.  
  13248.      U
  13249.  Up key
  13250.  UP key
  13251.  UPDATE statement
  13252.  UPDATE STATISTICS statement
  13253.  USE statement
  13254.  User connections configuration option
  13255.  User login ID/alias username list box
  13256.  User
  13257.    guest
  13258.    impersonate another
  13259.    special
  13260.  Username in database text box
  13261.  Username
  13262.    add using Admin menu
  13263.    add using SQL Query Window
  13264.    dbo
  13265.    delete using Admin menu
  13266.    delete using SQL Query Window
  13267.    display information on
  13268.    manage database
  13269.    manage using Admin menu
  13270.  Users, display current
  13271.    Admin menu
  13272.    SQL Query Window
  13273.  Utility programs
  13274.    bcp
  13275.    bldmastr
  13276.    console
  13277.    defncopy
  13278.    isql
  13279.    sqlservr
  13280.  
  13281.      V
  13282.  View
  13283.    as security mechanism
  13284.    database object
  13285.    permissions
  13286.    use to restrict access to data
  13287.  visitor login ID
  13288.  
  13289.      W
  13290.  Window menu
  13291.  Window, SQL Query
  13292.    add group
  13293.    add password
  13294.    add usernames
  13295.    change configuration options
  13296.    change Database Owner
  13297.    change default database
  13298.    change group
  13299.    change password
  13300.    create alias
  13301.    delete group
  13302.    delete login ID
  13303.    delete username
  13304.    display current users
  13305.    dump database
  13306.    dump transaction log
  13307.    load database
  13308.    manage groups
  13309.    remove alias
  13310.    truncate transaction log
  13311.  Windows
  13312.    alternate between
  13313.    clear
  13314.    SQL Query
  13315.    SQL Results Full
  13316.    SQL Results
  13317.  
  13318.  
  13319.