Microsoft SQL Server 2000 Super Management Manual (Nine)

xiaoxiao2021-03-06  59

9. Establish a database

Database structure

System database

Establish a database

View database

Delete database

Summary of this chapter

When you use the Database design of Microsoft SQL Server 2000 and installation, you can learn how to build a database. Compared with the early versions, SQL Server 2000's database is stored along with SQL Server 7's data. Early versions use logical devices and fixed-size data sections to place materials; SQL Server 2000 allows users to choose, whether they make files or archive groups to grow or shrink or narrow. This chapter will introduce the archives, archive groups, and how to manage the growth of the database. This chapter will introduce three ways to establish a database, and how to review and delete the database.

The database structure is composed of a set of system files, and the file can be combined to become a archive group. The archives group can easily manage management and classification, enhance system execution efficiency. In this section we will introduce the archives and archives groups, and their roles they play in the database. If the file is mentioned, the database is composed of a set of system files. System files can be divided into data files and log files. Data files are used to store data and objects (such as data sheets, indexes, view tables, triggers, pre-deposit procedures, etc.), and divided into main data files and secondary data files. Recording files are only used to store information about transaction records. The space of the file and the space of the file file is separated, and the record file cannot be regarded as part of the data file. Each database should include at least one data file and a record file, which cannot be shared with other databases. That is to say, the information and record files of this database can only belong to this database. Let's take a look at the three file types of the database. The main information archives, the main information files contain a systematic profile, such as the system database launch information and the system's information sheet and object. The main information file can also store the user-reserved information sheet and object. Each database can only have one (and must have one) main information file, the suggested file sub-file name is .mdf. The secondary data files will be stored in the data and objects that are not in the main data files. A database does not have to have a secondary information file (unlike the main information file must exist), you can choose to put all the information in the main data file. Some databases will utilize one or more secondary data files to disperse data in different disks. (This method is different from the RAID we will discuss in the next section), and the proposed sub-file name of the secondary data file is .ndf.

Transaction Record Archives This file records all transaction record information, which can be used to restore the information of the database. Each database must have at least one transaction record file. The suggested side file is called .ldf.

Note With a SQL Server material library, the maximum size of the data file is 32TB, and the file is 4TB.

With a simple database, a major information file can be stored all information, objects and a transaction record file. More complex databases may contain a primary information file, five secondary data files and two transaction record files. How do such a database integrate information about the distributed file files? The answer is: Using the archive group. The archive group archive group can group files to manage and store (a bit similar to the early version of SQL Server). The archives group disperse the database is built on multiple disks, disk control cards, or disk arrays (which is also the RAID discussed in Chapter 5) to strengthen the performance performance of the database. The profile group can be built on the specified disk using the archive group, which means that you can specify an entity disk, disk control card or disk array for a data sheet or an index I / O. There will be several examples of examples of this section. The archives group can be divided into three types: The main archive group includes primary data files, and files that are not placed in other archives groups. System Data Sheet - Define User, Items, and Database Permissions - All placed in major archives groups. When you build a database, SQL Server automatically establishes a system data sheet. The user's custom file group refers to the archive group of the user's customs in the process of establishing a database. In the specified user, you can build a data sheet and an index. The preset archive group If the data sheet and the index are not specified when the archive group is established, all data sheets and indexes are placed in the preset archive group. In each database, there is only one file group as a preset archive group. If no preset archive group group is specified, the preset value is the main archive group. Users who belong to the DB_OWNER role can switch the preset state from one archive group to another. At the same time, there can only be a preset archive group. We can use the Alter Database instruction to change the archive group, the following is the syntax of Transact-SQL: ALTER DATABASE DATABASE_NAME MODIFY FileGroup FileGroup_name

DEFAULT

(You will learn how to use T-SQL in . You can set the preset archive group into a user-reserve group, so that you can automatically create in the specified archive group, without each designated item which archive group group. Establish data sheets and index control data stored in different archive groups, enhance the data library performance. For example, you can place a commonly used data sheet in a large disk array (for example, a RAID composed of 10 disks), less useful data sheets are placed in one Small RAID. Therefore, more often accessible data sheets are allocated on multiple discs, allowing more disk I / O parallel. If you have multiple disks but don't use RAID, you can still use the archive group. For example, you can build your own files on their respective disks and put the files into their respective user custom archives groups. This will be placed in the specified file (and the disk where the file group is located) is placed in the specified file when you set a data sheet or index. Figure 9-1 is an example of this architecture: The main data file is placed in the main file group in the C disk, and the two secondary files are placed in the FG1 and FG2 of the user's customs in the E and F disks. In the archive group, the record file is placed in the G disk. You can then establish a data sheet and index in the user's custom file group -f1 or fg2.

Figure 9-1 Location using the archive group control information

Or you can disperse data on several disks through the user's custom file group. Figure 9-2 shows the secondary data files in the user's custom file group (FG1), respectively, respectively, respectively (the record file is in the disk G, the main data file is in the magnetic disc C). In this example, we assume that each database file is built in a single entity disk (not using RAID), using SQL Server's proportional write mode, can be established in the user's self-reserve architecture The data sheet and index are distributed in two different disks. Figure 9-2 Dispersion data using archive groups to multiple disks

If you are using a RAID system, you may need to put large data sheets, disperse on a logical disk array controlled by two or several RAID control cards. The setting method is to create a profile group of a user-reserve, and one file in the archive group exists in each control card. Assuming that you are on two different disk arrays, each of the secondary data files, each logical array consists of eight entity disks, setting on RAID 5, two arrays on a different RAID control card. To create a data sheet or index of a cross-control card (equal to 16 disk), first need to define a file group of users to place these two files, and then establish a data sheet in this archive group or index. Figure 9-3 Displaying the Archives Group (FG1) of the user's customs is dispersed in a sixteen entity disk (or two logical RAID disk arrays). The main data file is also shown on another control card (RAID1), and the file is recorded on the other RAID10 control card. SQL Server can automatically use the data file to configure the data in several disks in each data file to provide optimized automatic file configuration. "Striping" is the terminology of the database, which means that the data is distributed in more than one database file. The SQL Server file Stripping mode is independent of the RAID disk isometric magnetic area, which can be used alone or in mixed with RAID.

Figure 9-3 The user's custom file group is dispersed in several RAID control cards

When Stripping is made to the data file, SQL Server will compare the available space of each file, and then write data to each file, and write all the information to the first file, wait until the writing , Write the next file). Space Schedule (Extend) of the data sheet and the index. The range is the basic unit of configuring the space to the data sheet and the index, a range contains 8 pairs (Page), each page 8kb, so a range unit is 64KB. For example, if the file f1 has 400 MB of available space; file F2 has 100 MB free space, if you want to write 5 scope according to the proportionally fill the policy, 4 ranges are allocated to F1, 1 range Assigned to F2. In this way, the two files will be filled with substantially the same time, making the I / O effect of the across the magnetic disc. Regardless of the F1 and F2 files belong to the user's custom file group, it is still written in the main archive group. If the start size of all files in the archive group, when the data is loaded, it will be averaged to each file. It is recommended to set the start size of all files in the archive group to make the data across disk average to reach the I / O average assignment. Another benefit of the archive group is that the library backup can be based on the file or archive group. If your database is too big, you cannot back up all content, the file or archive group in the backup database, no need to back up the entire database. Chapter 32 of this book will detail how to make some backups using the archives group. When the rules and recommendations are used to use the archives and archive groups, remember the following SQL Server 2000 rules: Archives and archive groups can only be used for a repository. A file can only belong to a file group. Data and transaction record files cannot be in the same archive. Recording the space and the data file space should be managed separately. The transaction file file is not part of the archive group. Once the database is established, this file cannot be moved to another archive unless you delete this file and re-establish the file. In order to assist you with a database, the following is a few suggestions when using archives and archive groups: Most of the database only requires a data file and a transaction record file to operate smoothly. This design is recommended for I / O not a particularly dense database. As mentioned in Chapter 5, the record file and the data file must be placed in different entity disks. If you need to use multiple data files, you can set the primary data file to store system data sheets and objects, while users' data and objects set one or more secondary data files to store. In order to get the best performance, the archives and archive groups are established across multiple physical disks as much as possible to utilize the maximum number of parallel disk I / O. The non-clustered indexes that are often accessed and the non-clustered indexes contained in these data sheets are placed in the form of the archive group in different solid discs. If the file is in a different disk, the performance will be improved by parallel I / O. (The index will be discussed in Chapter 17.) If possible, put the data table used in the same query on a different entity disk, so when you search the information, you can use the parallel disk I / O . When a system uses RAID and many disks, the last two recommendations are not necessarily applicable. If you have a lot of disks, you should use the index and information tables to different disks as much as possible to utilize the maximum number of parallel disks I / O. Automated archive growth SQL Server allows files to grow automatically. When you create a file, you can specify whether SQL Server is allowed to grow automatically. It is recommended to set the file to allow automatic growth (the preset value is also set to allow automatic growth) because it can reduce the administrator manually monitor and increase the burden of file space. There is a starting size when the file is created.

When the starting space is filled, SQL Server will increase file space according to the specified growth amount, which is a growth increment value, and when the new space is filled, SQL Server will allocate new growth. Increment value. The data file will grow according to the specified amount, until the disk is full or reaches the maximum file size (if there is specified). Note that the file automatic growth is different from the ratio written. The automatic growth of the file is when the file is filled, SQL Server will automatically increase the file space;, the proportional writing refers to the SQL Server to store the data according to the remaining space of the file, and the data is stored, not the space of the file.

The largest file size file is the maximum size that can grow. This value is specified when the file is created, and the value of the maximum file size can be changed using the Enterprise Manager or the ALTER DATABASE command. If the maximum size of the file is not set, SQL Server will make the file grow up, until the disk space is used. In order to avoid lack of disk space in the disc server, you should set up the maximum size for each file to set up the SQL Server errors. If the file does grow to the maximum size, you can also use the ALTER DATABASE to reset the maximum file size, or add another file on the disk when there is space in the disk. If the file allows unlimited expansion (according to presets), when the disk space is exhausted, you must build the file on another disk with the remaining space. You should use the file automatic growth and maximum file size as the rules of design. When establishing a database, set the file to the maximum size that may grow. Although the growth of the file can be set to automatically grow, you still recommend monitoring the growth of the file regularly, which helps you estimate the future growth and decide whether the database should be modified to add more files. System Database When you install SQL Server, four system databases are created: Master, Tempdb, Model and MSDB Database. Master recording system level information, SQL Server installation information and configuration settings, and records all login accounts, other existing databases, and storage locations of the main files of all user databases. You should save the backup of the latest Master library. Tempdb is used to control temporary information lists and temporary pre-departments. This database is also required for temporary storage of SQL Server, such as sorting data. Each time SQL Server starts, a clean copy of a TEMPDB database is re-established according to Model's preset size. Then it will automatically grow up as needed. If you need a large Tempdb library space, you can use the Alter Database command to set a larger size preset. Online Series Search Tempdb Database Access for more information. The Model system creates a model of other databases, including the Tempdb database. When establishing a database, the first part is to establish a backup of the Model database. The rest of the database is filled by blank paging. There must be a Model database in the system, because each time SQL Server starts, you need to use the Model library to rebuild the Tempdb database. You can also modify the Model library, allowing it to include the user's self-reserve data type, information list, etc., so that each new database you create includes these properties. Online Series Search MODEL Database Access You can get more information. MSDB SQL Server Agent uses it to schedule work, warning, and record operator information. (Operator) is a person who is specified responsible for work and warning.) Each system database has its own main information file and record file. The database is stored in the directory specified by the system archive when installing SQL Server. Establishing a library SQL Server provides three ways to establish a database: use the establishment of the database wizard, SQL Server Enterprise Manager, and T-SQL instructions. The T-SQL instruction can be stored in the file and execute as the instruction code. The three methods will be discussed below: Use the establishment of the database wizard to pay attention to some of its restrictions. If you use the elves to establish a database, the created information files will be placed in the single magic disc of your specified, because the elf builds a database, there will be a step in which you specify the file in other locations (that is to say At the beginning of the designated location, all established data files are specified in the same disk and archive during the installation of the elves.

The record file can be placed in a different disk or file, but can only be stored in a single magouse. The user custom group cannot be specified, and the files will inherit the same growth option. It is recommended to use the establishment of the Database Elf when only one main information file and transaction record file are required in the database. If you want to put the secondary information file in a different disk with the main file, or you want to add the user's self-reserve archives group, or you need to specify the growth option for each file, you must use Enterprise Manager to use ENTERPRISE MANAGER. Or T-SQL instruction code to establish a database. Use the establishment of the Database Elf If you are a newcomer to establish a database, you can use the Database Spirit to establish a database. The following is the step of using the Elf: Open SQL Server Enterprise Manager, select a server to establish a database (first pressing the plus number next to Microsoft SQL Servers next to the plot to expand the folder, then expand the SQL Server group data clip, You can see the registered server). After selecting a server, select the tool / wizard on the functional table to enter the selection wizard dialogue, expand the database, as shown in Figure 9-4.

Figure 9-4 "Select Elf"

Establish a database wizard in two times to open a welcome to establish a library wizard dialogue, as shown in Figure 9-5.

Figure 9-5 "Welcome to the Establishment Database Elf" dialogue

Press Next to name the library and specify its location (as shown in 9-6), enter the database name, database file file, and transaction record files. If you choose ... you can browse the file. The path is specified and press next to the next step.

Figure 9-6 "Naming for the database and specifies its location" screen

Description This section will display how to create a database called MYDB, the main information file of this database is placed in C: / MSSQL2K / MSSQL / DATA, and the record file is placed in D: / MSSQL2K / MSSQL / DATA.

Figure 9-7 is a screen named by the database file. You can set the archive name and starting size of each database. The main information file will automatically use the database name as the pre-word, you can accept or enter the name, the deployment is called .mdf. If you know the size of the database file, you can enter the starting size value directly, otherwise you have left the preset value, which will use Enterprise Manger or Alter Database instructions to change. In addition to the main file set, other setup files are secondary files and automatically give files. Moral names. These files will be stored in the same directory as the primary file. Press Next to continue. There is no user-reservations group group option when using the Database Spirit. In the example, we keep the original preset main file (MyDB_DATA), add a secondary file and name mydb_data2. The two files will place at the same time at the position specified in step 3. If the specified file clip or archive group is placed on the disk you don't want to place, stop the elf installation step, we must use other methods to add a database. We will discuss how other new databases will be discussed next. Press Next to continue the new step.

Figure 9-7 "Named of the Database Archive" screen

A defined database archive has emerged (Figure 9-8). Usually, you recommend that you choose to automatically grow, allow the system to automatically grow the size of the database according to the needs of the database, and specify the database file should grow with a fixed increasing value, or the specified file grows according to the current file size. You can also choose the database file to grow automatically, to manually adjust the size of the database, but this will increase manual cost. You can also control the growth of the database file through the choice of unrestricted files to grow or restrict files. If you use the sprite new database, you cannot individually define the database file in step 4, that is, the use of the wizard adds a database, all the database added in step 4 will grow in the way as defined here. Continue to add steps as follows. Figure 9-8 "Defining the Database Archive Growth" screen

The name of the dialogue appears for the transaction record file. This dialog box and step 4 are very similar to the database file name, please be careful not to confuse the two dialogue. Setting logic as step 4, first enter the name and start size of the transaction record file (note that transaction record files record all repository modified records, which can be used to repair the data when the system is faulty). The system will automatically establish the first transaction data file and use the database name as the pre-word, of course, you can also customize the name. The sub-file name of the transaction file is. LDF, depending on the need to add a transaction record file. Unless you know the starting size of the trading file, it is recommended to reserve a preset value, and you can change this preset using the Enterprise Manager or ALTER DATABASE instruction in the future. Press Next to continue the next step. The definition transaction record file growth is displayed. The logic set here with step 5, you can specify the way the file grows. After the setting is complete, press another step to continue the next step. Complete the establishment of the Database Elf (Figure 9-9). Check if all new information is correct, confirm that the completion of the completion of the database can be completed, if you want to modify the information, press the previous step back to the previous screen.

Figure 9-9 "Completing the establishment of a database wizard" screen

The database has been successfully established. This means that the database is completed and press OK to complete the new step. There is a message. You have to establish a maintenance plan for the database. The recommended choice is. Maintenance Program ensures performance performance, regular backup to prevent system errors, and check the consistency of information. Here, please choose No, to be a thirtieth chapter we discuss the maintenance plan. Use Enterprise Manager SQL Server Enterprise Manager to establish a more complex database option than the elves. For example, you don't need to treat all files in the database as a file group, and you can define file growth options for each built file, or you can specify your own customized archive groups. The following describes how to use Enterprise Manager to establish a database. In the example, we will create a database called MYDB, which contains a primary file information, three secondary archive information of a user's custom architecture group.

Open Enterprise Manager. Expand the SQL Server group and expand the server. Press the right button on the database, then press the new repository.

The data library properties dialogue appears, first appears to be a general tab (Figure 9-10). Enter the new database name in the square.

Figure 9-10 "Normal" tab in the Database Properties dialogue

Press the Data Archive tab (Figure 9-11). Enterprise Manager automatically establishes primary data files, using the name of the database as a preamble, and as Primary as a archive group. You can change the main file name, location, or file size yourself, but you cannot change the archive group of the primary information file. Enter the archive name (logical name), location (entity name), size, and archive group group for each information file. In addition to the information files other than the main files, you can set the archive group of the user. In the example we create a secondary information file name MYDB_DATA2 in this archive group in MY_FG. Figure 9-11 "Data File" tab in the "Database Properties" dialogue

The location of the archive is in the disk data clip in SQL Sever. You can enter a new file or specify the file location with the browsing button. In the file properties option area, you can choose to make the file automatic growth and growth. You can also specify the size of the file. You can select unrestricted file growth to make the file unrestricted growth, or select the restriction file growth (MB) Specifies the size of the restricted file to grow (in MB). You can choose your settings now, or keep the preset value. If you want to change the preset value later, you will return to Enterprise Manager's database properties window changes. If you want to delete the file in the list, press the Delete button after you try to delete the file. After all the information file is set, press the Transaction Record Script Tab. The setting logic of the transaction record file is the same as the data file tab, but the archive group option is less because the transaction record file is not file group group. Enter the file name (logical name), location (entity name), size, and transaction record files and other starting sizes of all other files, select file automatic growth. After the database properties are defined, they will be added to the new. Now you can see the new database illustration on the right side. Use the T-SQL command You can use the T-SQL command or instruction code (Script) to create and modify the database without using the graphical user interface. To build a database, use the instruction code is useful. For example, when you have established a database in the graphical user interface, it is wrong, and the change mode is to remove the entire file and reset the correct position. But use the T-SQL command to make the wrong correction without reconstructing the database. You can also create another one-size database on other systems using the same document code. On the other hand, Enterprise Manager can be used to generate a T-SQL instruction code for establishing a database and a library object, but there must be a database existence before this action. The Enterprise Manager command creates all existing database settings, so you can use the generated instruction code as needed. No matter where you use the custom code, or use the generated instruction code, you recommend you to understand the T-SQL of the establishment database. We will review the T-SQL command to establish a database. You can store the instruction code in the file. Chapter 13 of this book will learn how to establish and execute instruction codes.

In this example, we will build a database named MyDB, which includes a primary information file (MYDB_ROOT), a secondary information file that is reserved in the preset main archive group (mydb_data1 ) And a transaction record file (LOG_DATA1). The following is a SQL statement that establishes MYDB:

Create Database MYDB

On

(Name = mydb_root, - Main Data Archives

Filename = 'c: / mssq12k/msql/data/mydbroot.mdf' ,size = 8MB,

MaxSize = 9MB,

FileGrowth = 100MB),

(Name = mydb_data1, - secondary data file

Filename = 'c: /msql2k/msql/data/mydbdata1.ndf',

Size = 100MB,

MaxSize = 1500MB,

FileGrowth = 100MB)

LOG ON

(Name = log_data1, - Recording file

Filename = 'D: /LOG_FILES/LOGDATA1.LDF',

Size = 1000MB,

MaxSize = 1500MB,

FileGrowth = 100MB)

In this example, you can see that the main information files and secondary data files are in the C disk, and the record files are in the E disk. As mentioned earlier, you should store data files and record files, respectively, to improve the I / O performance of the disc. At the same time, it is recommended to use .mdf, .ndf and .ldf as the secondary file name. Specify Size, MaxSize, and FileGRowth options in KB or MB, and the preset value will be in MB. XXXXXXX

Real world complex database This library example is based on several disks or magnetic disc arrays (in RAID systems). Here, "Disk" is a single disk device, or a magnetic disc array with a RAID disk area. We will establish several files on different disks, each file placed one of two archive groups. We named the database Sales and include the following files: Main information archives: Sales_Root.mdf three secondary data files in the Customers_Group archive group: Customer_Data1, Customer_Data2 and Customer_Data3 two times in the Products_Group archive group To be a profile: Product_Data1 and Product_Data2 A record profile: log_data1.ldf The following is the syntax of the establishment of the Sales repository. Because we will customize a data group, you will see the fileGroup keyword in the Create DataBes command.

Create Database Sales

On Primary - Clearly define the main archive group (this parameter can be available)

(Name = Salesroot, - Main Data Archives

Filename = 'c: / mssq12k/mssql/data/salesroot.mdf',

Size = 8MB,

MaxSize = 10MB,

FileGrowth = 1MB),

FileGroup Customers_Group - Profile Group of Secondary Information Archives

(Name = Customer_Data1,

FileName = 'D: /Mssq12k/mssql/data/costomerdata1.ndf',

Size = 800MB,

MaxSize = 100MB,

FileGrowth = 100MB),

(Name = Customer_Data2, - Secondary Information Archive

FileName = 'E: /Mssql2/msql/data/costomerdata2.ndf' ,size = 800MB,

MaxSize = 1000MB,

FileGrowth = 100MB),

(Name = Customer_Data3, - Secondary Information Archive

FileName = 'f: /msq12/msql/data/costomerdata3.ndf',

Size = 800MB,

MaxSize = 1000MB,

FileGrowth = 100MB),

Filegroup Products_Group - Another archive group

(Name = Product_Data1, - Secondary Information Archive

Filename = 'g: /msq12/mssql/data/product_data1.ndf',

Size = 500MB,

MaxSize = 700MB,

FileGrowth = 100MB),

(Name = Product_Data2, - Secondary Information Archive

FileName = 'h: /msq12/msql/data/product_data2.ndf',

Size = 500MB,

MaxSize = 700MB,

FileGrowth = 100MB)

LOG ON

(Name = logData1, - Recording file

Filename = 'i: /log_files/logdata1.ldf',

Size = 800MB,

MaxSize = 1000MB,

FileGrowth = 200MB)

Referring to the annotation in the example, if the file is not defined before the file is deposited, the file will be preset to the main archive group. If you define a archive group before depositing a file, the file will be placed in the archive group according to the definition. As shown in the example, after defining the two archives groups of CUSTOMERS_GROUP and Products_Group, the files immediately after the archive group will be placed in the archive group. After a file group definition, all files listed will be stored in this archive group until another archive group is defined, or is executed to the LOG ON. Also pay attention to the disk code for each file. Each file is established on different disks in different disks in those archives groups to disperse data into different disks. For example, a data sheet established in Customers_Group will store the data in accordance with the proportion (in stripping mode) to the disk of Customer_Data1, Customer_Data2, and Customer_Data3 files. The record file is also in a separate disk without the information file, so that the record file can be written in order. In the preset state, SQL Server allows the data file to grow as needed until the disk space is used. Therefore, if you do not want to allow the growth of the database file to grow more than the beginning of the established size, you must set fileGrowth = 0, so that the file will be filled with the start size you set up before. When your data is a static data sheet (not growing information table, you will not write information), you can choose this setting. In this case, you don't need to specify a maxSize value because the maximum size is the beginning of the size setting.

Note If you have used SQL 6.5 or earlier, you will find that the SQL 7.0 version does not use the Disk init command to establish a logical device before the database is created. The logic device is now replaced by using the file. After reviewing the database database, you can use Enterprise Manager, or the osql of the command column to perform the SQL command to browse and see the objects in the database. The following will introduce these two methods: Using Enterprise Manager: Steps to review the database information using Enterprise Manager:

In Enterprise Manager, expand the server name and database data clip where the SQL Server group / library is located, as shown in Figure 9-12.

Figure 9-12 Expand Enterprise Manager and Database Drawings

Select a database search information, as shown in Figure 9-13.

Figure 9-13 Items showing objects in the Northwind database

Using SQL You can also use the command to prompt the window, or perform the T-SQL command in Query Analyzer to view the database information, first open the command prompt window first, connect the command prompt window, connect to SQL Server with OSQL, as follows The example shows:

Osql -u -p -s

When entering the above command, correct the data within the cornence parentheses (not corneum brackets). Do the following SQL commands list the database information.

Use mydb - Specifies which database environment is executed

Go

Sp_helpfile - Display all file information of the database, you can also provide the file name

To specific archives

Go

SP_HELPDB MYDB - The above information plus the space size of the file allocation

Go

SP_HELPFILEGROUP - Displays the archive group information in the database, you can also provide the archive group name

Symptom information

Go

sp_helpdb - View all database information

Go

Information You can find details related to these commands and output methods in the SQL Server line series.

Deleting a library is sometimes you may need to delete a database. It should be noted that once the database is deleted, it is not possible to perform any reply steps. If you want to find the repository, you must restore the backup version. For security, you will be backed up before deleting the database to prevent you in the future. You can use Enterprise Manager or SQL command to delete the database. Chapter 8, using Enterprise Manager, has been mentioned that Enterprise Manager can perform database management, or to view information. You can perform the following steps, permanently delete the database and all profiles:

In Enterprise Manager, expand the SQL Server group, press two to remove the server name of the database. Expand the database folder to display the database. Press the right button on the database name you want to delete, then select the delete from the fast display function, will delete the database message, if you choose to delete the backup and restore the process library, all belongs to the MSDB database Backup - Restore History Record Data Sheets - Restore Information will be deleted, after selecting, press OK to confirm the deletion database.

Note The Master database is not allowed to be deleted.

Use SQL you can use the T-SQL command to delete the database. To use T-SQL, you must turn on the Query Analyzer or command prompt window. Refer to the following example: OSQL -U -p -s

The deletion of the database is permanent, and the DROP DATABASE command can be used to delete the database and all files. The following steps to delete the MYDB database:

Use master - You must use the Master database to perform DROP DATABASE

command

Go

DROP DATABASE MYDB - Database Name is the only parameter that needs to be entered

Go

After deleting the database, it is recommended that you build a new backup for the Master Database to maintain the latest user database, avoid the deleted database data in the Master database. It is important to note that when the user is connected to the database, it is unable to delete the database. Therefore, please confirm that the user does not have the database. This chapter summarizes in this chapter, you learned more about information, record files, archives groups, and files automatically. Database is also established through the establishment of the database wizard, SQL Server Enterprise Manger, and T-SQL commands, and learn two methods for review databases and archive materials and delete databases. The next chapter will begin to study in the database.

转载请注明原文地址:https://www.9cbs.com/read-110849.html

New Post(0)