Friday, 17 October 2014

Part 2 Creating and Drop a Database

In  part 1 What is SQL Server we understand the concept SQL Server 2008 and How to connect to SQL server. In this Session we understand how to create or delete the database. There are two ways to do almost everything in SQL Server 2008

  • Graphically with SSMS
  • With Query
First we talk How to create or delete Graphically

open your SSMS go to object Explore Right click on database folder and select New Database.


Part 2 Creating and Drop a Database

After that a New Database dialog box appear

Set the Database Name <DB Name> what ever you want My is Sample 1 and click OK

Expand Database folder and new database is created name Sample 1.
If database is not shown for some reason just Right click  Database folder and refresh .

Now we create a database using Query

Create Database <DB_Name>

When we create a database behind the scenes two files are created
to get to the file Right click the database and click properties

Properties Window opens. select file Go to the path

Copy that path and past to run window.. to open run click window button + R.
There are 2 files .mdf and log.ldf

these two file are associated  with a database we created.
.mdf is actual database file (Master Database File)
.log.ldf is Transaction log file (its a recovery file)

Now we discuss how to rename the DB graphically
just Right Click the DB and click rename

there are two ways to write a query for rename DB

Alter Database <Original name> Modify Name = <New Name>
OR
By system store procedure. store procedure are covered later session For now understand they are only a group of commands.
and there are 2 types of store procedure user define store procedure and system store procedure as name suggest user store procedure are created by user and system store procedure are provided by

Execute sp_renameDB'OldName','NewName'

Now we discuss how to delete DB
Grapically
Right Click DB and click Delete

By Query

drop database <DB Name>

No comments:

Post a Comment