Starting Microsoft SQL Server

Posted by: rahul.vairagi068

Tagged in: Untagged 

After installing Microsoft SQL Server, you can start using it. 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. To check it (on Microsoft Windows XP Professional, Windows Vista , Windows Server 2003, or Windows Server 3008) you can open Control Panel and the Administrative Tools. In the Administrative Tools window, you can open the Services. In the Services window, check the status of the SQL Server (MSSQLSERVER) item:

 

Services

If the MSSQLSERVER service is stopped, you must start it. To do this, you can right-click it and click Start. If it fails to start, check the account with which you logged in:

  • If you are using Microsoft Windows XP Professional 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 2003 or Microsoft Windows Server 2008), make sure you logged in with an account that can start a service

Once the service has started, it should be labeled Started:

Services

Opening Microsoft SQL Server

 

To launch Microsoft SQL Server, you can click Start -> (All) Programs -> Microsoft SQL Server 2008 -> SQL Server Management Studio

Launching Microsoft SQL Server 2008

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

Practical LearningPractical Learning: Launching Microsoft SQL Server

 
  1. Start the computer
  2. Log in with the account you used to install Microsoft SQL Server
  3. To launch Microsoft SQL Server, click Start -> (All) Programs -> Microsoft SQL Server 2008 -> SQL Server Management Studio. A splash screen will appear:
     
    Splash Screen
  4. On the Connect to Server dialog box, click Cancel

The Microsoft SQL Server Management Studio

 

 

Introduction

 

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

Microsoft SQL Server Management Studio

The top section of the SQL Server Management Studio displays the classic title bar of a regular window, with an icon on the left, followed by the title of the application, and the system buttons on the right side.

The Main Menu

 

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

The Standard Toolbar

 

The Standard toolbar displays under the main menu:

The Standard toolbar displays under the main menu

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

Context-Sensitve Menu

The Object Explorer

 

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

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

Dragging

You can drag and drop to one of those placeholders.

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

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

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

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

Object Explorer

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

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

Connection to a Server

 

  

Using Connect to Server

 

In order to do anything significant in Microsoft SQL Server, you will have to log in. If you start Microsoft SQL Server Management Studio from the Start button, the Connect To Server dialog box would come up. If you 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 New Query
  • In the Object Explorer, click the arrow of the Connect button and click one of the options, such as Database Engine...
     
    Connect

Any of these actions would display the Connect to Server dialog box:

Connect to Server

From there, select the name of the server and the type of authentication to use.

Once you are ready, click Connect. If you log in successfully, the Object Explorer would appear with a few nodes:

Microsoft SQL Server Management Studio

After 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 Close
  • On the main menu, click File -> Exit
  • Press Alt, F, X

Using the Command Prompt

 

Besides the SQL Server Management Studio, you can also work on Microsoft SQL Server from the DOS command prompt. This is done using an application or command named SQLCMD.EXE. To use it, open the Command Prompt, type SQLCMD (case-insensitive) and press Enter.

The Command Prompt

After using Microsoft SQL Server from the command prompt, to close it, type Quit (case-insensitive) and press Enter. To close the DOS window:

  • Type Exit (case-insensitive) and press Enter
  • Click the system Close button Close

Using the Windows PowerShell

 

When Microsoft SQL Server 2008 is installed, it also installs the Windows PowerShell 1.0, which is a new command-based application from Microsoft. Besides the SQL Server Management Studio and the Command Prompt, you can use PowerShell to create and manage databases. To access it, you can click Start -> (All) Programs -> Windows PowerShell 1.0 -> Windows PowerShell. A DOS window would display:

Windows PowerShell

Notice that the title bar displays Windows PowerShell.

To access Microsoft SQL Server from PowerShell, type SQLCMD and press Enter:

Windows PowerShell

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

After using the PowerShell, to exit from Microsoft SQL Server, type Quit (case-insensitive) and press Enter:

Windows PowerShell

To close PowerShell and the DOS window, you can:

  • Type Exit (case-insensitive) and press Enter
  • Click the system Close button Close

Microsoft SQL Server Logins

 

 

Introduction

 

In order to access something (such as a computer or a database), the object must be authenticated. Such an object can use a username and a password. In the adsence of this, a user would receive an error:

Login Error

An object can also take advantage of the group it belongs to. For this reason, the ability to be authenticated in order to access the database or resource is called a login.

Creating a Login

 

Before creating a login, the person for whom you want to create the account must have a user account on the computer. If you are using Microsoft Windows XP-7, the person must have a loca user account on the computer. If you are working on a server, the person must have an account in the domain. You can create a login either visually or with code.

To visually create a login, in the Object Explorer, expand the Security node. Right-click Login and click New Login...

New Login

This would display the Login - New dialog box. In the Login Name text box, type the user name of the person whose account you are creating. The account must have been created already in the computer (Microsoft Windows XP-7) or on the server. If you provide a user name that cannot be found in the system, when trying to finalize, you would receive an error:

Login Error

After entering the user name, you must specify how the user would be authenticated. You have a choice between the operating system and Microsoft SQL Server.

The formula to programmatically create a login is:

CREATE LOGIN loginName { WITH <option_list1> | FROM <sources> }

<option_list1> ::= 
    PASSWORD = { 'password' | hashed_password HASHED } [ MUST_CHANGE ]
    [ , <option_list2> [ ,... ] ]

<option_list2> ::=  
    SID = sid
    | DEFAULT_DATABASE =database    
    | DEFAULT_LANGUAGE =language
    | CHECK_EXPIRATION = { ON | OFF}
    | CHECK_POLICY = { ON | OFF}
    | CREDENTIAL =credential_name <sources> ::=
    WINDOWS [ WITH <windows_options>[ ,... ] ]
    | CERTIFICATE certname
    | ASYMMETRIC KEY asym_key_name<windows_options> ::=      
    DEFAULT_DATABASE =database
    | DEFAULT_LANGUAGE =language

To let Microsoft SQL Server generate skeleton code for you, on the Standard toolbar, click New Query to get a text editor. in the Template Explorer, expand the Login node, drag Create SQL Login Must Change Password and drop it in the empty text editor:

-- =================================================
-- Create SQL Login Must Change Password template
-- =================================================

CREATE LOGIN <SQL_login_name, sysname, login_name> 
WITH PASSWORD = N'<password, sysname, Change_Password>' 
MUST_CHANGE,
CHECK_POLICY = <check_policy,ON or OFF, ON>;
GO

You start with the CREATE LOGIN expression, followed by the user name. To specify a password after that, type PASSWORD = N' '. In the single-quotes, enter the desired password. When creating a login, you must specify a password. You can just set a temporary password. One of the options you can specify is to make the user change his or her password the next time he or she logs on. To apply this, after the password, add the MUST_CHANGE flag.

Practical LearningPractical Learning: Creating a Login

 
  1. In the Object Explorer, expand the server name if necessary and expand Security
  2. Right-click Login and click New Login...
  3. In the Login Name text box, type operez
  4. Click SQL Server Authentication
  5. In the Password text box, type Password1 and press Tab
  6. In the Confirm Password text box, type Password1
    New Login
  7. Accept the three check boxes and make sure User Must Change Password At Next Login is checked.
    Click OK
  8. On the Standard toolbar, click the New Query button New Query
  9. To programmatically create a login, type the following:
    CREATE LOGIN rkouma
    WITH PASSWORD = N'Password1';
    GO
  10. On the Standard toolbar, click the Execute button Execute
     
    Creating a Login
  11. Click inside the Query window and press Ctrl + A
  12. To create two more accounts with three options, type the following:
    CREATE LOGIN pkatts
    WITH PASSWORD = N'Password1'
    MUST_CHANGE,
    CHECK_POLICY = ON,
    CHECK_EXPIRATION = ON;
    GO
    CREATE LOGIN gdmonay
    WITH PASSWORD = N'Password1' 
    MUST_CHANGE,
    CHECK_POLICY = ON,
    CHECK_EXPIRATION = ON;
    GO
  13. Press F5 to execute
     
    Creating a Login
  14. In the Object Explorer, expand Login under Security if necessary. To refresh it, right-click Logins and click Refresh
    Make sure you have logins for the gdmonay, the pkatts, the operez, the rkouma, and the sa accounts
     
    Logins
  15. Close Microsoft SQL Server
  16. When asked whether you want to save something, click No

Using a Login

 

After creating a login, a person can use it to connect to the server. There are many options.

After launching Microsoft SQL Server, in the Connect To Server dialog box, in the Authentication combo box, the person can (must) select SQL Server Authentication, then enter his/her login name and a password.

Remember that when Microsoft SQL Server is installed, it creates a default account named sa. You can also use it as a login and provide its password:

Connect to Server

If the SQL Server Management Studio is already opened, to log in, on the Standard toolbar, a person can click Connect -> Database Engine...

Connect

This would open the Connect to Server dialog box. The person must select SQL Server Authentication in the Authentication combo box, enter or select a login name in the Login combo box, and type a password:

Connect to Server

Then click Connect. In the same way, you can create as many connections as possible, using valid login accounts.

Another alternative is to switch user (Start -> Switch User) and log in with a different account. In this case, if a person launches Microsoft SQL Server, the Authentication can be set as Windows Authentication:

Connect to Server

The person would not have to enter a password.

Practical LearningPractical Learning: Using a Login

 
  1. To start it again, click Start -> (All) Programs -> Microsoft SQL Server 2008 -> SQL Server Management Studio
  2. In the Authentication combo box, select SQL Server Authentication
  3. In the Login combo box, type operez
  4. In the Password text box, type Password1
     
    Connect
  5. Click Connect
  6. In the dialog box that comes up, enter the password as P@ssword1 and press Tab
  7. In the other text box, type  P@ssword1
     
    Change Password
  8. Click OK
  9. In the Object Explorer, click Connect and click Database Engine...
  10. In the Authentication combo box, select SQL Server Authentication
  11. In the Login combo box, type rkouma
  12. In the Password text box, type Password1
  13. Click Connect
  14. In the dialog box that comes up, enter the password as P@ssword1 and press Tab
  15. In the other text box, type  P@ssword1
  16. Click OK
  17. In the same way, connect to the database engine using the pkatts and the gdmonay accounts