SQL Server creates a database

Source: Internet
Author: User

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

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.