How To Create Database In Sql Server 2008 Using Query
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
- Feedback
- Edit
Create a Database
- 3 minutes to read
Thank you.
Applies to: SQL Server (all supported versions)
This article describes how to create a database in SQL Server by using SQL Server Management Studio or Transact-SQL.
Limitations and restrictions
- A maximum of 32,767 databases can be specified on an instance of SQL Server.
Prerequisites
- The CREATE DATABASE statement must run in autocommit mode (the default transaction management mode) and is not allowed in an explicit or implicit transaction.
Recommendations
-
The master database should be backed up whenever a user database is created, modified, or dropped.
-
When you create a database, make the data files as large as possible based on the maximum amount of data you expect in the database.
Security
Permissions
Requires CREATE DATABASE permission in the master
database, or requires CREATE ANY DATABASE, or ALTER ANY DATABASE permission.
To maintain control over disk use on an instance of SQL Server, permission to create databases is typically limited to a few SQL Server login.
Use SQL Server Management Studio
To create a database
-
In Object Explorer, connect to an instance of the SQL Server Database Engine and then expand that instance.
-
Right-click Databases, and then select New Database.
-
In New Database, enter a database name.
-
To create the database by accepting all default values, select OK; otherwise, continue with the following optional steps.
-
To change the owner name, select (...) to select another owner.
Note
The Use full-text indexing option is always checked and dimmed because, beginning in SQL Server 2008, all user databases are full-text enabled.
-
To change the default values of the primary data and transaction log files, in the Database files grid, select the appropriate cell and enter the new value. For more information, see Add Data or Log Files to a Database.
-
To change the collation of the database, select the Options page, and then select a collation from the list.
-
To change the recovery model, select the Options page and select a recovery model from the list.
-
To change database options, select the Options page, and then modify the database options. For a description of each option, see ALTER DATABASE SET Options (Transact-SQL).
-
To add a new filegroup, select the Filegroups page. Select Add and then enter the values for the filegroup.
-
To add an extended property to the database, select the Extended Properties page.
-
In the Name column, enter a name for the extended property.
-
In the Value column, enter the extended property text. For example, enter one or more statements that describe the database.
-
-
To create the database, select OK.
Use Transact-SQL
To create a database
-
Connect to the Database Engine.
-
From the Standard bar, select New Query.
-
Copy and paste the following example into the query window and select Execute. This example creates the database
Sales
. Because the keyword PRIMARY is not used, the first file (Sales_dat
) becomes the primary file. Because neither MB nor KB is specified in the SIZE parameter for theSales_dat
file, it uses MB and is allocated in megabytes. TheSales_log
file is allocated in megabytes because theMB
suffix is explicitly stated in theSIZE
parameter.
USE master; GO CREATE DATABASE Sales ON ( NAME = Sales_dat, FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\saledat.mdf', SIZE = 10, MAXSIZE = 50, FILEGROWTH = 5 ) LOG ON ( NAME = Sales_log, FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\salelog.ldf', SIZE = 5MB, MAXSIZE = 25MB, FILEGROWTH = 5MB ); GO
For more examples, see CREATE DATABASE (SQL Server Transact-SQL).
Next steps
- Database Files and Filegroups
- Database Detach and Attach (SQL Server)
- ALTER DATABASE (Transact-SQL)
- Add Data or Log Files to a Database
Feedback
How To Create Database In Sql Server 2008 Using Query
Source: https://docs.microsoft.com/en-us/sql/relational-databases/databases/create-a-database
Posted by: leboeuffroir2002.blogspot.com
0 Response to "How To Create Database In Sql Server 2008 Using Query"
Post a Comment