Minggu, 15 Februari 2009

Microsoft SharePoint Team Blog
The official blog of the Microsoft SharePoint Product Group

Creating a Database Using SQL




To open the code editor, in the Object Explorer, right-click the name of the server and click New Query
In the empty window, type:
CREATE DATABASE RealEstate1
ON PRIMARY
( NAME = DataRepository, FILENAME = 'C:\Microsoft SQL Server Database Development\RealEstate1.mdf')
LOG ON
( NAME = DataLog, FILENAME = 'C:\Microsoft SQL Server Database Development\RealEstate1.ldf')
GO


To execute the statement, press F5

Using Code Template



To specify more options with code, Microsoft SQL Server ships with various sample codes you can use for different assignments. For example, you can use sample code to create a database. The sample codes that Microsoft SQL Server are accessible from the Template Explorer.

To access the Template Explorer, on the main menu, you can click View -> Template Explorer. Before creating a database, open a new query window. Then:

To create a new database using sample code, in the Template Explorer, expand the Databases node, then drag the Create Database node and drop it in the query window. The new database would be created in the server that holds the current connection
If you have access to more than one server, to create a database in another server or using a different connection, in the Template Explorer, expand the Databases node, right-click Create Database and click Open. In the Connect to Database Engine dialog box, select the appropriate options, and can click OK
With any of these actions, Microsoft SQL Server would generate sample code for you:

-- =============================================
-- Create database template
-- =============================================
USE master
GO

-- Drop the database if it already exists
IF EXISTS (
SELECT name
FROM sys.databases
WHERE name = N''
)
DROP DATABASE
GO

CREATE DATABASE
GO
You would then need to edit the code and execute it to create the database. From the previous lessons and sections, we have reviewed some characters uch as the comments -- and some words or expressions such as GO, CREATE DATABASE, and SELECT. We will study the other words or expressions in future lessons and sections.

Database Maintenance


Introduction



If you have created a database but don't need it anymore, you can delete it. It is important to know, regardless of how you create a database, whether using SQL Server Management Studio, code in the query window, or the Command Prompt, every database can be accessed by any of these tools and you can delete any of the databases using any of these tools.

As done with creating a database, every tool provides its own means.

SQL Server Management Studio



To delete a database in SQL Server Management Studio, in the Object Explorer, expand the Databases node, right-click the undesired database, and click Delete. A dialog box would prompt you to confirm your intention. If you still want to delete the database, you can click OK. If you change your mind, you can click Cancel.

Practical Learning: Deleting a Database



In the Object Explorer, right-click MotorVehicleAdministration and click Delete

In the Delete Object dialog box, click OK
Deleting a Database Using SQL



To delete a database in SQL Query Analyzer, you use the DROP DATABASE expression followed by the name of the database. The formula used is:

DROP DATABASE DatabaseName;
Before deleting a database in SQL, you must make sure the database is not being used or accessed by some one else or by another object.

Practical Learning: Deleting a Database With Code



On the Standard toolbar, click the New Query button
To delete a database, type:
DROP DATABASE RealEstate1;
GO


Press F5 to execute the statement



source : http://blogs.msdn.com/sharepoint/default.aspx