How to create database in SQL server
To create a database in SQL Server, you can use SQL Server Management Studio (SSMS) or execute SQL commands using a query window. Here's a step-by-step guide on how to create a database:
Using SQL Server Management Studio (SSMS):
- Open SSMS and connect to your SQL Server instance.
- In the Object Explorer pane, right-click on the "Databases" node and select "New Database."
- In the "New Database" dialog box, provide a name for your database in the "Database name" field.
- Optionally, specify the owner of the database in the "Owner" field.
- Set the desired options for data and log file locations, file sizes, and file growth settings.
- Click the "OK" button to create the database.
Using SQL Commands:
- Open SSMS and connect to your SQL Server instance.
- Open a new query window by clicking "New Query" in the toolbar or pressing Ctrl+N.
- Execute the following SQL command to create a new database:
CREATE DATABASE YourDatabaseName;
Replace "YourDatabaseName" with the desired name for your database.
4. Optionally, you can specify additional options such as file locations and file growth settings. Here's an example:
Make sure to replace the file paths and sizes with your preferred values.
CREATE DATABASE YourDatabaseName
ON
(NAME = 'YourDatabaseName_Data',
FILENAME = 'C:\Data\YourDatabaseName.mdf',
SIZE = 10MB,
MAXSIZE = UNLIMITED,
FILEGROWTH = 5MB)
LOG ON
(NAME = 'YourDatabaseName_Log',
FILENAME = 'C:\Data\YourDatabaseName.ldf',
SIZE = 5MB,
MAXSIZE = 100MB,
FILEGROWTH = 5MB);
5. Execute the query by clicking the "Execute" button or pressing F5.
After executing the command or completing the steps, the database will be created in SQL Server. You can then start using it to store and manage your data.