Before creating a login, the person for whom you want to create the account must have a user account. In some cases the account must be on the computer. In some other cases, the person must have an acccount on the network. In other words, the person must have an account that allows him or her to establish a connection either on the local computer or on the network. If you are using Microsoft Windows XP-7, the person must have a local 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 Microsoft SQL Server, in the Object Explorer, expand the Security node. Right-click Login and click New Login...
This would display the Login - New dialog box:
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 After creating a login, a user can use it to connect to the server. There are many options, as we will see in the next few sections. After launching Microsoft SQL Server, in the Connect to Server dialog box, the user must select the type of server. This is done in the Server Type combo box:
In most cases, and for our lessons, we will use the Database Engine option. If the SQL Server Management Studio is already opened, to log in, the user can click Connect -> Database Engine...
The user must specify what computer has Microsoft SQL Server. If working from the Connect to Server dialog box, the user can select a computer in the Server Name. If the user had previously used Microsoft SQL Server, the dialog box would display the name of the computer he previously connected to and he can simply click Connect. If the user wants to connect to another computer on the network, that is, a computer other than the one selected, he can type the computer name or select it in the Server Name combo box. Another option is to click the arrow of the Server Name combo box and select <Browse for more...>:
In this case, intermediary steps allow the user to select the computer. After selecting the computer, in the Authentication combo box, the user must specify the type of authentication to use. There are various choices. If the user is working from PowerShell or from the Windows command prompt, to connect to a local computer, he can type SQLCMD -S followed by the name of the computer and press Enter. You can include space between -S and the name of the server. Here is an example:
You can also omit the space between -S and the name of the server. Here is an example:
As we will see later on, to use Microsoft SQL Server, the user must provide a user name and a password. In reality, Microsoft SQL Server 2008 requires every user to log in but it provides various options. If the user already has a login, when he starts the computer an logs in to the operating system, when he launches Microsoft SQL Server, if the application recognizes his login account, he can log in without providing a user name and a password. If you are visually creating a login and if you want the Microsoft Windows operating system to take care of logging, in which case the user will be able to connect to Microsoft SQL Server without providing a user name and a password, click the Windows Authentication radio button (it is the default and should be selected already: If you are creating the login with code, add the FROM WINDOWS flag: CREATE LOGIN See Below
FROM WINDOWS
When Windows Authentication is used or if you add the FROM WINDOWS flag, when the Connect to Server dialog box comes up, the user can select Windows authentication and click Connect.
If working from the Connect to Server dialog box, if the user selects SQL Server Authentication, he would have to provide a login name. Of course, the login must have been created. If you are visually creating a login, in the Login Name text box, type the user name of the person whose account you are creating. If you are creating the login in the same computer where Microsoft SQL Server is installed (Microsoft Windows XP-7), type the user name as it was created in the computer. If you are creating the login for a user account on the server (domain), type the name of the domain, followed by \, and followed by the user name as it exists in the domain. Here is an example:
Of course, the user's account must have been created already in the computer (Microsoft Windows XP-7) or on the server (domain). If you provide a user name that cannot be found in the system, when trying to finalize, you would receive an error.
If the user decides to use SQL Server Authentication, after specifying a login name, he must also provide a password, which must be associated with the login. If you are visually creating the login, to provide a password, first click the SQL Server Authentication radio button. Then click the Password text box and type the desired password. Click the Confirm Password text box and type the same password. If you are programmatically creating the login, to specify the password, after the login name, type WITH PASSWORD = and provide the password in single-quotes. 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:
Microsoft SQL Server allows a user to connect with many login account. After connecting, to make another connection, the user can click Connect -> Database Engine, and provide the necessary pieces of information as we had seen in this section. In the same way, you can create as many connections as possible, using valid login accounts.
Disconnecting neither closes Microsoft SQL Server nor shuts down the server. It simply closes the connection to the server. If a persons wants to use the server again, she must connect.
The Object Explorer displays a list of items as a tree. One of the most regularly used items will be the name of the server you are using. If you are just starting to learn database development or you are a junior database developer, you may use or see only one server. In some cases, you may be dealing with many servers. Regardless, you should always know what server you are currently connecting to. This is easy to check with the first node of the Object Explorer. In the following example, the server is named Central:
If you are connected to more than one server, each is represented by its own node:
The name of the server is followed by parentheses. In the previous section, we saw that, to establish a connection to a server, you must authenticate yourself. In some cases you may use the same account over and over again. In some other cases you may have different accounts that you use for different scenarios, such as one account for database development, one account for database management, and/or one account for database testing. When many connections have been made, each connection is represented in the Object Explorer by its own node and each connection has its own objects (sub-nodes):
To close a connection, you can right-click it and click Disconnect:
Some operations cannot be performed by some accounts. When performing some operations, you should always know what account you are using. You can check this in the parentheses of the server name. In the following connection, an account named Administrator is currently logged in to a server named Central:
We saw that, by default, the right area of Microsoft SQL Server Management Studio displays an empty gray window. When you select something in the Object Explorer, you can use that right area to display more detailed information about the selected item. To do this, on the main menu, click View -> Object Explorer Details. The main area on the right side would then be filled with information:
Probably the most regular node you will be interested in, is labeled Databases. This node holds the names of databases on the server you are connected to. Also, from that node, you can perform almost any necessary operation of a database. To see most of the regularly available actions, you can expand the Databases node and some of its children. You can then right-click either Databases or one of its child nodes. For example, to start PowerShell, you can right-click the Databases node or the server name and click PowerShell:
When the PowerShell comes up, what it displays depends on what you had right-clicked.
|
|
|||||||||||||||||||||||||||||
|