Database Reference
In-Depth Information
Logins
When creating logins and users, you must be connected to the master database. You then can use the
CREATE LOGIN command as follows:
CREATE LOGIN loginname WITH PASSWORD = ' password '
You must use the WITH PASSWORD option and specify a password. Several options you may be used to
from using SQL Server locally aren't support in SQL Azure, such as DEFAULT_DATABASE and
DEFAULT_LANGUAGE . Chapter 6 discusses the CREATE LOGIN command in more detail.
Users
Now that you've created a login, let's create a user based on it. This is also simple. The syntax is nearly
equivalent to the local syntax:
CREATE USER username
This syntax works if there is a login with the same name. For example, the following is valid:
CREATE LOGIN myuser WITH PASSWORD = 'T3stPwd001'
CREATE USER myuser
However, the following fails:
CREATE LOGIN myuser WITH PASSWORD = 'T3stPwd001'
CREATE USER myotheruser
You must use the FROM LOGIN clause when creating a user whose username differs from that of the
login name:
CREATE USER username FROM LOGIN loginname
Thus, the correct syntax is the following:
CREATE LOGIN myuser WITH PASSWORD = 'T3stPwd001'
CREATE USER myotheruser FROM LOGIN myuser
Note SQL Azure doesn't support GUEST accounts. When you create a user, it must be based on an existing
login.
OK, enough about creating databases, users, and logins. Chapter 6 talks more about SQL Azure-
specific T-SQL syntax when it discusses programming with SQL Azure in detail. Let's wrap up this
chapter with a simple example of how to connect an application to a SQL Azure database.
Connecting to a SQL Azure Database
You have to hand it to Microsoft for going above and beyond in some areas of Azure. The fact that it
provides you with connection strings to use in your applications is just plain cool. If you flip back to
Figure 3-3, notice the button labeled, appropriately enough, Connection Strings. As soon as you select a
database in the list, the Connection Strings button becomes enabled. Clicking it brings up the dialog
shown in Figure 3-12, which provides you with two connections strings (one .NET and the other ODBC)
to use in your applications to connect to the selected SQL Azure database.
Search WWH ::




Custom Search