Structured Query Language (SQL) tutorial
Using SQL to Create a SQL Server Database
We'll create a database called bus that contains details of bookings for our company XYZ Transport. The details we plan to store include customer names, dates and times, buses, destinations, customer and drivers' addresses, phone numbers etc.
Both the MSDE server and client need to be running for you to work with your database. The MSDE server started when you logged in to Windows because it was installed as a service. You need to start the application that you are using as a client to connect to the database (SQL Buddy). To do this:
- Select Start > All Programs > SQLBuddy. The Connection Profiles Window opens:
- Click Add. The Edit Connection Profile dialog will open.
- Enter your given name in the New Profile textbox (1).
- Right-click My Computer on your computer’s Start menu
- Select Properties from the shortcut menu to reveal your computer’s System Properties information box.
- Select the Computer Name tab.
- Enter the computer name on this tab into SQL Buddy’s Edit Connection Profile dialog as the name of your MSDE / SQL Server (2).
- Check Use trusted Connection (3).
- Test your connection (4 ). You will be advised whether your test succeeded or not. If not, check your computer name and try again.
- Once you have successfully set up a profile, close the Edit Connection Profile dialog. Your new profile has been added to the Connection Profiles.
Now that your have established your profile, you can connect to MSDE by double-clicking your profile.
After you connect to the server, you can create a database, as follows:
- Type
create database bus;
Remember that all SQL commands must end with a semi-colon (;).
- Click the Run button,
.
The MSDE server responds with something like
Statement Completed Succesfully
Local Execution Duration (ms): 734
Last Run: 11:18 AM
The CREATE DATABASE process is allocating 0.63 MB on disk 'emp'.
The CREATE DATABASE process is allocating 0.49 MB on disk 'emp_log'.
This means that you have successfully created the database.
Now, let's see how many databases you have on your system.
- Issue the following command.
sp_databases;
The server responds with a list of databases:
(Some of the databases have been obscured in this figure. This should not be the case for your server)
Here we have several databases, some created by MSDE during installation and our bus database.You should see your newly-created bus database on this list.