Today, a guy said to create a database, made a half-day did not fix, accustomed to the graphical interface, these things have forgotten all back to the teacher ...
1 Use [Master]2 GO3 IF EXISTS(SELECT 1 fromsysdatabasesWHERENAME=N'hktemp')4 BEGIN5 DROP DATABASEHktemp--Delete Database First if database exists6 END7 GO8 CREATE DATABASEhktemp9 onTen PRIMARY --creating the primary database file One ( ANAME='hktemp', -FILENAME='E:\Databases\HkTemp.dbf', -SIZE=5MB, theMaxSize=20MB, -FileGrowth=1MB - ) - LOG on --Create a log file + ( -NAME='Hktemplog', +FileName='E:\Databases\HkTemp.ldf', ASize=2MB, atMaxSize=20MB, -FileGrowth=1MB - ) - GO - --Add Table - IF not EXISTS(SELECT * fromSys.objectsWHERE object_id = object_id(N'Hksj_user') andTypeinch(N'U')) in BEGIN - CREATE TABLEHksj_user to ( +IdINT IDENTITY(1,1) not NULL, -SNameNVARCHAR( -) not NULL, theSnicknameNVARCHAR( -), *SpasswordNVARCHAR( -) not NULL, $DcreatedateDATETIME ,Panax NotoginsengScreatorNVARCHAR( -), -SemailNVARCHAR( -), theSphoneNVARCHAR( -), +SidentifyidNVARCHAR( -), ADlasttimelogonDATETIME the PRIMARY KEY CLUSTERED + ( -IdASC $) with(Ignore_dup_key= OFF) on [PRIMARY] $) on [PRIMARY] - END - GO the --Add Comment - EXECSys.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'Wuyi GO the EXECSys.sp_addextendedproperty@name=N'ms_description',@value=N'Email',@level0type=N'SCHEMA',@level0name=N'dbo',@level1type=N'TABLE',@level1name=N'Hksj_user',@level2type=N'COLUMN',@level2name=N'Semail'
SQL Server SQL statement creation database