T-SQL Introduction to create and view data

Source: Internet
Author: User
Tags filegroup microsoft sql server mssql mssqlserver create database

Creating a Database

IF db_id (' MyDatabase6 ') is not NULL

DROP DATABASE MyDatabase6;

CREATE DATABASE MyDatabase6

On PRIMARY

(--Master information file

NAME = ' Logicnameofdatafile6_1 ',

FILENAME

= ' C:/Program files/microsoft SQL server/mssql10. Mssqlserver/mssql/data/datafile6_1.mdf ',

Size = 5MB,--Set Initial size

MAXSIZE = 100MB,--set maximum storage space for data files

FileGrowth = 15%--Set the automatic growth rate

),

FILEGROUP Userfg6_2--Assigning a database file datafile6_2.ndf to a filegroup userfg6_2

(--Secondary information file

NAME = ' Logicnameofdatafile6_2 ',

FILENAME

= ' C:/Program files/microsoft SQL server/mssql10. Mssqlserver/mssql/data/datafile6_2.ndf ',

Size = 2MB,--Set Initial size

MAXSIZE = 100MB,--set maximum storage space for data files

FileGrowth = 10%--Set the automatic growth rate

),

FILEGROUP Userfg6_3--Assigning a database file datafile6_3.ndf to a filegroup userfg6_3

(--Secondary information file

NAME = ' Logicnameofdatafile6_3 ',

FILENAME

= ' C:/Program files/microsoft SQL server/mssql10. Mssqlserver/mssql/data/datafile6_3.ndf ',

Size = 3MB,--Set Initial size

MAXSIZE = 100MB,--set maximum storage space for data files

FileGrowth = 5%--Set the automatic growth rate

)

LOG on (

--Set the logical name of the log file

NAME = ' LogicNameOfLogFile6 ',

--Set Log file

FILENAME

= ' C:/Program files/microsoft SQL server/mssql10. Mssqlserver/mssql/data/logfile6.ldf.ldf ',

Size = 10MB,--Set Initial size

MAXSIZE = 100MB,--set maximum storage space for data files

FileGrowth = 1MB--Set the automatic growth rate

)

View Database

There are several ways to view the database, you can view system tables, or you can use system stored procedures

SELECT Type_desc,

Name

Physical_name,

Size

Max_size,

Growth

From Sys.database_files--View System Aísys.database_files

Go

sp_helpdb

Stored procedure sp_helpdb provides the ability to view basic information about a database, which is actually an encapsulation of several T-SQL commands

These commands extract data from the related system tables and get basic database information.

The syntax is as follows

sp_helpdb database name

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.