Creation of SQL Server Database
We can create Database in 2 ways :
- Using GUI
- Using T-SQL Script
Step 1: From the Windows Start Menu, select “Microsoft SQL Server”, and then “SQL Server Management Studio”. Once the Management Studio starts, connect to the SQL instance then right click the Databases folder and select new Database. Enter a name in the “Database name” text box.
Step 2: Click on new database and provide the database name
For this example, well use the name “MyNewDB”.
- Logical Name:
MyNewDB – Data file is where the actual data is saved on the hard drive.
MyNewDB_log – Log file keeps track of any changes to that data.
- File Type:
Data files will be defined as ROWS and Log file will be defined as LOG
Primary: The Primary data file contains the start-up information for the database and points to the other files in the database. User data and objects can be stored in this file or in secondary data files. Every database has one primary data file and. The recommended file name extension for primary data file is .mdf
Transaction Log: The Transaction log files hold the log information that is used to recover the database. There must be at least one log file for each database. The recommended file name extension for transaction logs is .ldf , we can add multiple Log files to database.
Secondary: Secondary data files are optional, user-defined, and store user data. Secondary files can be used to spread data across multiple disks by putting each file on a different disk drive. Additionally, if a database exceeds the maximum size for a single Windows file, you can use secondary data files so the database can continue to grow.
- Initial Size(MB):
It always recommended to give some initial size for a user defined database based on Database average DB growth. SQL Server files can grow automatically from their originally specified size. When you define a file, you can specify a specific growth increment. Every time the file is filled, it increases its size by the growth increment. If there are multiple files in a filegroup, they will not auto grow until all the files are full. Growth then occurs using round-robin algorithm. The default value can be set 100MB for .MDF and 1024MB for .LDF. Later will analyse the DB average growth by monthly and can set Initial size for MDF file.
It always recommended to set auto growth for both .mdf and, ldf files Initially we can set auto growth512MB later can change the value based on the growth of DB.
For .mdf- should be given in MB’s (Recommended)
For .ldf should be given in MB’s or Percent (ex10%) depends on the expected size of your log file.
You have select the path based on your requirement to be placed .MDF and .LDF files in drive.
- File Name:
We do not need to provide any file name since files will get generated automatically based on Logical name once click OK. If you want to give any separate name, then you can provide.
Using T-SQL Script:
Use the bellow T-SQL script and execute in master
CREATE DATABASE Sales
( NAME = MyNewDB,
FILENAME = ‘c:\program files\microsoft sql server\mssql\data\MyNewDB.mdf’,
SIZE = 102400kb,
MAXSIZE = 10MB,
FILEGROWTH = 10MB )
( NAME = ‘Sales_log’,
FILENAME = ‘c:\program files\microsoft sql server\mssql\data\ MyNewDB_log.ldf’,
SIZE = 102400KB,
MAXSIZE = 10MB,
FILEGROWTH = 10% )
Reference Link – https://sqldbahouse.blogspot.in/2017/03/creation-of-sql-server-database-for.html?spref=fb
Posted by Sheikvara