Home

Database Creation With the SQL Query Analyzer

 

Introduction

The command used to create a database in SQL uses the following formula:

CREATE DATABASE DatabaseName

The CREATE DATABASE (remember that SQL is not case-sensitive, even when you include it in a C++ statement) expression is required. The DatabaseName factor is the name that the new database will carry. Although SQL is not case-sensitive, as a C++ programmer, you should make it a habit to be aware of the cases you use to name your objects.

As done in C++, every statement in SQL can be terminated with a semi-colon. Although this is a requirement in many implementations of SQL, in Microsoft SQL Server, you can omit the semi-colon. Otherwise, the above formula would be

CREATE DATABASE DatabaseName;

Here is an example:

To assist you with writing code, the SQL Query Analyzer includes sections of sample code that can provide placeholders. To access one these codes, on the main menu of SQL Query Analyzer, click File -> New... Then, in the General property page of the New dialog box, you can double-click a category to see the available options.

Practical LearningPractical Learning: Creating a Database Using the SQL Query Analyzer

  1. To open the SQL Query Analyzer, on the toolbar of the SQL Server Enterprise Manager, click Tools -> SQL Query Analyzer
  2. In the empty window, type:
     
    CREATE DATABASE GeneralSports
    GO
  3. Execute the statement

Using a Wizard

To easily create a database using sample code, on the toolbar of SQL Query Analyzer, you can click the arrow of the New Query button on the toolbar, position the mouse on Create Database and click Create Database Basic Template:

An option from the menu fills the query window with code:

As an alternative, on the main menu of SQL Query Analyzer, you can click File -> New... Then, in the New dialog box, select a category, followed by an option, and click OK. This also would write a few lines of code for you and you  can then change the sections of code that need to be changed. Whenever necessary, we will show what you should change to customize the code generated by the wizard.

 

Practical LearningPractical Learning: Completing a Database From Sample Code

  1. On the main menu of SQL Query Analyzer, click File -> New...
  2. In the General property page of the New dialog box, double-click Create Database
     
  3. Accept the Create Database Basic Template option and click OK
     
  4. Change the code as follows:
     
  5. Press F5 to execute the statement
  6. Close the window, when asked whether you want to save, click Yes
  7. Locate your My Documents folder and display it in the Save In combo box
  8. Enter the name as MotorVehicleDivision and press Enter
 

Previous Copyright © 2005-2016, FunctionX Next