Use SQL scripts to create SQL Server database Sample statements

Source: Internet
Author: User

The following describes how to create an sqlserver Database Code Template, and a template for creating a table. During development, you can copy it and change it directly.

Hope you can help me! Copy code The Code is as follows: use [Master]
Go
If exists (select 1 from sysdatabases where name = n' hktemp ')
Begin
Drop database hktemp -- if the database exists, delete the database first.
End
Go
Create Database hktemp
On
Primary -- create a master database file
(
Name = 'hktemp ',
Filename = 'e: \ databases \ hktemp. dbf ',
Size = 5 MB,
Maxsize = 20 mb,
Filegrowth = 1 MB
)
Log On -- create a log file
(
Name = 'hktemplog ',
Filename = 'e: \ databases \ hktemp. ldf ',
Size = 2 MB,
Maxsize = 20 mb,
Filegrowth = 1 MB
)
Go
-- Add a table
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 (20) not null,
Snickname nvarchar (20 ),
Spassword nvarchar (30) 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 = OFF) on [primary]
) On [primary]
End
Go
-- Add comments
Exec sys. sp_addextendedproperty @ name = n' MS _ description', @ value = n' ', @ 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.