To create a SQL Server database instance statement _mssql

Source: Internet
Author: User
Tags create database
The following is a code template for creating a SQL Server database, plus a template to create a table. The development of the time can copy the past direct changes can be used.

I hope I can help!
Copy Code code as follows:

Use [master]
Go
IF EXISTS (SELECT 1 from sysdatabases WHERE name=n ' hktemp ')
BEGIN
DROP Database Hktemp--If a database exists, delete it first
End
Go
CREATE DATABASE Hktemp
On
PRIMARY--Create master database files
(
Name= ' Hktemp ',
Filename= ' E:\Databases\HkTemp.dbf ',
SIZE=5MB,
MAXSIZE=20MB,
Filegrowth=1mb
)
Log on--Creating a journal file
(
Name= ' Hktemplog ',
Filename= ' E:\Databases\HkTemp.ldf ',
SIZE=2MB,
MAXSIZE=20MB,
Filegrowth=1mb
)
Go
--Adding tables
IF not EXISTS (SELECT * from sys.objects WHERE object_id = object_id (n ' hksj_user ') and type in (n ' U '))
BEGIN
CREATE TABLE Hksj_user
(
Id INT IDENTITY (1,1) not NULL,
Sname NVARCHAR is not NULL,
Snickname NVARCHAR (20),
Spassword NVARCHAR () not NULL,
Dcreatedate DATETIME,
Screator NVARCHAR (20),
Semail NVARCHAR (50),
Sphone NVARCHAR (50),
Sidentifyid NVARCHAR (30),
Dlasttimelogon DATETIME
PRIMARY KEY CLUSTERED
(
Id ASC
) with (Ignore_dup_key = out) on [PRIMARY]
) on [PRIMARY]
End
Go
--Add comments
EXEC sys.sp_addextendedproperty @name =n ' ms_description ', @value =n ' login name ', @level0type =n ' SCHEMA ', @level0name =n ' dbo ', @ Level1type=n ' TABLE ', @level1name =n ' Hksj_user ', @level2type =n ' COLUMN ', @level2name =n ' sname '
Go
EXEC sys.sp_addextendedproperty @name =n ' ms_description ', @value =n ' mailbox ', @level0type =n ' SCHEMA ', @level0name =n ' dbo ', @ Level1type=n ' TABLE ', @level1name =n ' Hksj_user ', @level2type =n ' COLUMN ', @level2name =n ' Semail '
Related Article

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.