How to create Database in Sql Server ?

Introduction:

In this article, we will learn, How to create database in Sql Server? and How to change or select database? and How to find Sql Server database file's locations?

SQL Create Database Statement:

SQL Server Create Database Statement is use for create database with in server.

SYNTAX:

CREATE DATABASE database_name

Arguments:

database_name: Database name which identifies database with in the Sql Server. Database name should not exceeds more than 128 characters.

CREATE DATABASE Example:

SQL Server Create Statement will create database SWCDB as follows.

--Creating SWCDB Database in Sql Server
CREATE DATABASE SWCDB
Go

Sql USE Statement:

Sql Use Statement is used to select or Change database in Sql Server.

After database creation, Select or change Current Database as follows.

-- Select SWDB Database for working
USE SWDB
Go

Note: When we creates new database, it will creates two files with database_name with .mdf and .LDF extensions, in Sql Server computer at default location. .LDF appends database_name with _log.

SQL Server Database Files and Location

SQL Server view sys.database_files is used to find database file name and location with in Server as follows.

-- View physical files location for connected database.
SELECT * FROM sys.database_files

OUTPUT:

namephysical_name
CampusLiveMultilingualV3D:\SWC SQL DB\SWCDB.mdf
CampusLiveMultilingualV3_logD:\SWC SQL DB\SWCDB_log.LDF

If you have any query or question or topic on which, we might have to write an article for your interest or any kind of suggestion regarding this post, Just feel free to write us, by hit add comment button below or contact via Contact Us form.


Your feedback and suggestions will be highly appreciated. Also try to leave comments from your valid verified email account, so that we can respond you quickly.

 
 

{{c.Content}}

Comment By: {{c.Author}}  On:   {{c.CreatedDate|date:'dd/MM/yyyy'}} / Reply


Categories