You are on page 1of 25

Because Microsoft SQL Server works as a service to the operating system,

in order to use it, you must make sure its service has started. Sometimes
you will have to start the service and sometimes you will have to stop it. To
check it, you can open the ControlPanel and the Administrative Tools. In
the Administrative Tools window, open the Services.
In the Services window, check the status of the SQL Server
(MSSQLSERVER), the SQL Server Agent (MSSQLSERVER), and the SQL
Server Browser:

he Services window, check the status of the SQL Server (MSSQLSERVER), the SQL
ver Agent (MSSQLSERVER), and the SQL Server Browser:

e MSSQLSERVER service is stopped, you should start it. To do this, you can rightk it and click Start. If it fails to start, check the account with which you logged in:
If you are using Microsoft Windows 7 and you logged in as Administrator but did
not provide a password, you should open Control Panel, access User Accounts,
open the Administrator account, and create a password for it
If you are using a server
(Microsoft Windows Server 2008 or Microsoft Windows Server 2012), make sure

you logged in with an account that can start a service


metimes you will launch Microsoft SQL Server and try to connect but you may
ive an error message stating that the connection could not be established even
ugh you know that the username is correct. If that happens, check the service and
t it.

e the service has started, it should be labeled Started.

ning Microsoft SQL Server

aunch Microsoft SQL Server, you can click Start -> (All) Programs -> Microsoft SQL
ver 2012 -> SQL Server Management Studio

en it starts, it would present a dialog box that expects you to log in.

Start the computer


Log in with the account you used to install Microsoft SQL Server
To launch Microsoft SQL Server, click Start -> (All) Programs -> Microsoft SQL
Server 2012 -> SQL Server Management Studio.
A splash screen will appear:

On the Connect to Server dialog box, click Cancel

e Microsoft SQL Server Management Studio

oduction

re are many tools you will use in Microsoft SQL server. One of them is called
rosoft SQL Server Management Studio. To access it, you can click Start -> (All)
grams -> Microsoft SQL Server 2012 -> SQL Server Management Studio. A dialog
would come up but you can click Cancel on it:

top section of the SQL Server Management Studio displays the classic title bar of a

ular window, with an icon on the left, followed by the title of the application, and the
em buttons on the right side.

Main Menu

er the title bar, the menu bar displays categories of menus that you will use to
orm the various necessary operations.

Standard toolbar displays under the main menu:

Standard toolbar is just one of the available ones. Eventually, when you perform an
on that would benefit from another toolbar, the Microsoft SQL Server Management
dio would display that toolbar. Still, if you want to show any toolbar, you can rightk any menu item on the main menu or any button on a toolbar. A menu would come

Object Explorer

left side of the interface displays, by default, the Object Explorer window, with its
bar labeled Object Explorer. If you don't see it, on the main menu, you can click
w -> Object Explorer.

Object Explorer is a dockable window, meaning you can move it from the left side
nother side on the interface. To do this, you can click and drag its title bar to a
tion of your choice. When you start dragging, small boxes that represent the
sible placeholders would come up:

can drag and drop to one of those placeholders.

Object Explorer is also floatable, which means you can place it somewhere in the
dle of the interface:

lace the window back to its previous position, you can double-click its title bar. The
dow can also be tabbed. This means that the window can be positioned either
ically or horizontally.

ny time, if you do not want the Object Explorer, you can close or hide it. To close the
ect Explorer, click its close button.

the right side of the Object Explorer title, there are three buttons. If you click the
button that points down, a menu would appear:

menu allows you to specify whether you want the window to be floated, docked, or
bed.

right side of the window is made of an empty window. This area will be used to
lay either the contents of what is selected in the Object Explorer, or to show a
ult of some operation. As you will see later on, many other windows will occupy the
t section but they will share the same area. To make each known it will be
esented with a tab and the tab shows the name (or caption) of a window.

r using Microsoft SQL Server Management Studio, you can close it. To do this:
Click the icon on the left side of Microsoft SQL Server Management Studio and
click Close
On the right side of the title bar, click the system Close button
On the main menu, click File -> Exit

Press Alt, F, X

nnecting to Microsoft SQL Server

oduction

rder to do anything significant in Microsoft SQL Server, you will have to establish a
nection to it. If you start Microsoft SQL Server Management Studio from the Start
on, the Connect To Server dialog box would come up:

ou had started from the Start button but clicked Cancel, to connect to a server:
On the main menu, click File -> Connect Object Explorer...

On the Standard toolbar, click the New Query button


In the Object Explorer, click the arrow of the Connect button and click one of the
options, such as Database Engine...
of these actions would display the Connect to Server dialog box.

r starting the computer and logging in, on the Connect to Server dialog box, the
abase Engine option would be selected in the Server Type combo box. The name of
computer should be selected in the Server Name combo box. As an alternative, if
rosoft SQL Server is installed on the computer you are using, you can set the Server
e as (local) .
easiest way to connect is to select Windows Authentication in the Authentication
bo box. The User Name combo box should have the name of the computer, followed
back slash, and followed by the user name of the account that is currently logged
You don't have to enter a password (this is because you are using Windows
hentication and because you are logged in already):

ng the SQL Command Prompt

des the SQL Server Management Studio, you can also work on Microsoft SQL
ver from the DOS Command Prompt. To access the command Prompt, click the Start
on:
If you are using Microsoft Windows XP or 7, click the box that appears,
type cmd and press Enter
If you are using Microsoft Windows Server, click Command Prompt

e at the Command Prompt, type SQLCMD (case-insensitive) and press Enter.

r using Microsoft SQL Server from the command prompt,


Quit (case-insensitive) and press Enter. To close the DOS window:

to

close

it,

Type Exit (case-insensitive) and press Enter


Click the system Close button

ng the Windows PowerShell

en Microsoft SQL Server 2012 installs, it also installs an application named Windows
erShell, which is a command-based application from Microsoft. Besides the SQL

ver Management Studio and the Command Prompt, you can use PowerShell to
ate and manage databases. To access it:
Access the Command Prompt as seen above, type sqlps, and press Enter

At the Command Prompt, type SQLCMD and press Enter


Click Start -> (All) Programs -> Windows PowerShell 1.0 -> Windows PowerShell
If you had already started Microsoft SQL Server, in the Object Explorer, right-click
the name of the computer or the Databases node and click Start PowerShell

oth cases, a DOS window would display:

ce that the title bar displays Windows PowerShell. To access Microsoft SQL Server
m PowerShell, typeSQLCMD and press Enter:

ce that, this time, the title bar displays SQLCMD, which indicates that the
ication is ready to receive commands that relate to Microsoft SQL Server.

r using the PowerShell, to exit from Microsoft SQL Server, type Quit (casensitive) and press Enter:

abase Creation

oduction

atabase is primarily a group of computer files that each has a name and a location. There are diffe
s to create a database. To visually create a new database in Microsoft SQL Server Management Stu
he Object Explorer, you can right-click the Databases node and click New Database... This would o
New Database dialog box.

ractical Learning: Introducing Databases

Start the computer and log in


Start Windows Explorer

In the left frame, click the C: drive. If you already have a folder named Microsoft SQL Server Datab
Development, fine. If not, right-click a blank area in the right frame -> New -> Folder. Type Micros
SQL Server Database Development as the name of the new folder

Start Microsoft SQL Server. In the Server Name combo box, make sure the name of the computer is
selected. In the Authentication combo box, make sure Windows Authentication is selected. Make su
the account you are using is selected in the User Name combo box

Click Connect

Name of a Database

Unless stated otherwise (we will mention the exceptions, for example with variables, tables, etc), a
name will start with either a letter (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, A, B
D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, or Z) or an underscore
After the first character, we will use any combination of letters, digits, or underscores
A name will not start with two underscores
If the name is a combination of words, at least the second word will start in uppercase. Examples
areCountries Statistics, Global Survey, _RealSport, FullName, or DriversLicenseNumber

r creating an object whose name includes space, whenever you use that object, include its n
ween [ and ]. Examples are [Countries Statistics], [Global Survey], or [Date of Birth]. Even if
created an object with a name that doesn't include space, when using that name, you can still includ
square
brackets.
Examples
are [UnitedStations], [FullName], [DriversLicenseNumb
[Country].

abase, in the Database Files section and under the Initial Size column, change the size as you wish.

ractical Learning: Setting the Database File Size

In the Database Files section, click the box under the Initial Size column header, click the up arrow
the spin button and increase its value to 5

Location of a Database

ou should be aware of already from your experience on using computers, every computer file must h
ath. The path is where the file is located in one of the drives of the computer. This allows the opera
em to know where the file is, so that when you or another application calls it, the operating sys
ld not be confused.

default, when you create a new database, Microsoft SQL Server assumes that it would be loca
rive:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA folder. If you use
w Database dialog box of the SQL Server Management Studio, if you specify the name of the datab
click OK, the interpreter automatically creates a new file, and appends the .MDF extension to the
is the (main) primary data file of your database.

ou do not want to use the default path, you can change it. If you are using the New Database dialog
hange the path, under the Path header, select the current string:

You might also like