0% found this document useful (0 votes)
81 views

SQL 2

This document discusses creating, altering, and dropping databases in SQL Server. It provides the following information: 1. Databases can be created graphically using SQL Server Management Studio or by using queries. 2. To alter a database, the ALTER DATABASE command or sp_renameDB stored procedure can be used. 3. To drop a database, the DROP DATABASE command is used. Dropping a database deletes the .mdf and .ldf files.

Uploaded by

jhansi rani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views

SQL 2

This document discusses creating, altering, and dropping databases in SQL Server. It provides the following information: 1. Databases can be created graphically using SQL Server Management Studio or by using queries. 2. To alter a database, the ALTER DATABASE command or sp_renameDB stored procedure can be used. 3. To drop a database, the DROP DATABASE command is used. Dropping a database deletes the .mdf and .ldf files.

Uploaded by

jhansi rani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

Sql server, .

net and c# video tutorial


Free C#, .Net and Sql server video tutorial for beginners and intermediate
programmers.

Support us .Net Basics C# SQL ASP.NET Aarvi MVC Slides C# Programs


Subscribe Download
Creating, altering and dropping a database - Part 2
In Part 1 of SQL Server, we have seen, using SSMS to connect to SQL Server. In this
part we will learn creating, altering and dropping a database.

A SQL Server database can be created, altered and dropped


1. Graphically using SQL Server Management Studio (SSMS) or
2. Using a Query

To create the database graphically


1. Right Click on Databases folder in the Object explorer
2. Select New Database
3. In the New Database dialog box, enter the Database name and click OK.

To Create the database using a query


Create database DatabaseName

Whether, you create a database graphically using the designer or, using a query,
the following 2 files gets generated.
.MDF file - Data File (Contains actual data)
.LDF file - Transaction Log file (Used to recover the database)

To alter a database, once it's created


Alter database DatabaseName Modify Name = NewDatabaseName

Alternatively, you can also use system stored procedure


Execute sp_renameDB 'OldDatabaseName','NewDatabaseName'

To Delete or Drop a database


Drop Database DatabaseThatYouWantToDrop

Dropping a database, deletes the LDF and MDF files.

You cannot drop a database, if it is currently in use. You get an error stating -
Cannot drop database "NewDatabaseName" because it is currently in use. So, if other
users are connected, you need to put the database in single user mode and then drop
the database.
Alter Database DatabaseName Set SINGLE_USER With Rollback Immediate
With Rollback Immediate option, will rollback all incomplete transactions and
closes the connection to the database.

Note: System databases cannot be dropped.


Email This
BlogThis!
Share to Twitter
Share to Facebook
Share to Pinterest
7 comments:

AnonymousJune 22, 2015 at 12:38 AM


Hi Venkat,

Is it possible to add sample links of scriptlets or snippets of databases and


tables as a part of your download.

Additionally, TSQL based programming functions and procedures tutorials will be a


good start for beginners.

thanks

Reply

UnknownApril 2, 2016 at 4:59 AM


Hi Venkat,

If the size of the .LDF file is getting increased in GBs so how to decrease the
size of it. In my case the size is increased about 48GB. I have tried with shrink
option but it is not working.

Thanks.

Reply
Replies

UnknownMay 16, 2019 at 12:20 PM


Simple take log backup of database and perform DBCC Shrink file operation on it.

Reply

UnknownJanuary 6, 2018 at 7:41 AM


if we drop the database .ldf file will be deleted.then how it is used to recover
the database?

Reply

information BasketNovember 25, 2018 at 6:52 PM


hi Mr. venkat,

i need to take sql sever course with you

Reply

TrinathDecember 26, 2019 at 1:47 AM


Hi sir
Is there any chance to create the Files with Query
Reply

Sagar PatelJuly 21, 2020 at 12:14 AM


Hi Venkat,

In this blog, as per you said if we delete the database both .mdf and .ldf will be
deleted but if we rename the database, Will the actual database name in file path
be changed?

I found in my case that if I rename the database, the change in database name is
not reflecting in the actual file path, so what's the reason behind it?

Thanks

Reply

It would be great if you can help share these free resources

Newer PostOlder PostHome


Subscribe to: Post Comments (Atom)
Pragim Technologies - Best software training and placements in marathahalli,
bangalore. For further details please call 09945699393.

Complete Tutorials
How to become a full stack web developer

Cloud computing complete tutorial

Healthy food for healthy mind and body

JavaScript tutorial

Bootstrap tutorial

Angular tutorial for beginners

Angular 5 Tutorial for beginners

Important Videos
The Gift of Education

Web application for your business

How to become .NET developer

Resources available to help you

Dot Net Video Tutorials


Blazor tutorial

C tutorial

ASP.NET Core Tutorial

ASP.NET Core Razor Pages Tutorial

Angular 6 Tutorial
Angular CRUD Tutorial

Angular CLI Tutorial

Angular 2 Tutorial

Design Patterns

SOLID Principles

ASP.NET Web API

Bootstrap

AngularJS Tutorial

jQuery Tutorial

JavaScript with ASP.NET Tutorial

JavaScript Tutorial

Charts Tutorial

LINQ

LINQ to SQL

LINQ to XML

Entity Framework

WCF

ASP.NET Web Services

Dot Net Basics

C#

SQL Server

ADO.NET

ASP.NET

GridView

ASP.NET MVC

Visual Studio Tips and Tricks

Dot Net Interview Questions

Slides
Entity Framework

WCF
ASP.NET Web Services

Dot Net Basics

C#

SQL Server

ADO.NET

ASP.NET

GridView

ASP.NET MVC

Visual Studio Tips and Tricks

Java Video Tutorials


Part 1 : Video | Text | Slides

Part 2 : Video | Text | Slides

Part 3 : Video | Text | Slides

Interview Questions
C#

SQL Server

Written Test
Powered by Blogger.

You might also like