Today we take some time to learn about SQL Server databases, including how to create databases, create tables, SQL Server data types, data integrity, design databases, SQL Server security models, and T-SQL statements, and so on. I hope you can have some gains after reading it. Well, first we look at how to create a database, here we create the database and the next article created by the table will be used in the future, I hope you notice! T-the syntax for SQL database creation is as follows:CREATE DATABASEDatabase name on [PRIMARY] ( <Data file Parameters> [,. .. n] [< file group parameters >] ) [LOG on] ( <Log file parameters> [,. .. n] ) [ ]Represents an optional parameter, T-SQL syntax often requires querying the help of SQL Server, which is frequently seen in Help. As we all know, the simplest statement that creates a database is the CreateDATABASEDatabase name, that is, we omitted some options with default values! Let's use T.-SQL to do a complete example of creating a database: UseMaster--set the current database to master for access to the sysdatabases tableGOIF EXISTS(SELECT * fromsysdatabasesWHEREName='Studb')DROP DATABASEStudbCREATE DATABASEStudb on PRIMARY --the default belongs to the primary primary filegroup, which omits(NAME='Studb_data',--logical name of the master data fileFILENAME='E:/project/studb_data.mdf',--physical name of the master data fileSIZE=5MB,--Primary Data file Initial sizeMAXSIZE=100MB,--maximum number of main data file growthFileGrowth= the% --growth rate of master data files)LOG on(NAME='Studb_log', FILENAME='E:/project/studb_log.ldf', SIZE=2MB, FileGrowth=1MB)GObefore we built the library, we would detect the existence of the STUDB database and, if so, delete it and rebuild it. Where does the database reside? Where are we going to test it? Because the new database is registered in the System Database Master table sysdatabases, we only need to look at the name column of the sysdatabases table of the master database! Note here the usage of the EXISTS (query statement) detection statement, which returns TRUE if the query statement returns more than 1 records, or False if a record is present that satisfies the condition. This way our database is created successfully.
SQL Server creates a database