The following describes how to create an sqlserver DatabaseCodeTemplate, and a template for creating a table. During development, you can copy it and change it directly.
Hope you can help me!
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 primary 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'