Working with SQL Server
Learn how to connect and log into SQL Server, how to issue SQL Server statements, and how to obtain information about databases and tables.
In this lesson, you learn how to connect and log into SQL Server, how to issue SQL Server statements, and how to obtain information about databases and tables. You also create the example tables we’ll be using throughout this book.
Making the Connection
Now that you have a SQL Server DBMS and client software to use with it, it would be worthwhile to briefly discuss connecting to the database.
SQL Server, like all client/server DBMSs, requires that you log into the DBMS before you’re able to issue commands. SQL Server can authenticate users and logins using its own user list or using the Windows user list (the logins used to start using Windows). As such, depending on how SQL Server is configured, it may log you in automatically using whatever login you used for Windows itself, or it may prompt you for a login name and password.
When you first installed SQL Server, you may have been prompted for an administrative login (often named sa for system administrator) and a password. If you are using your own local server and are simply experimenting with SQL Server, using this login is fine. In the real world, however, the administrative login is closely protected because access to it grants full rights to create tables, drop entire databases, change logins and passwords, and more.
To connect to SQL Server, you need the following pieces of information:
The hostname (the name of the computer). This is localhost or your own computer name if you’re connecting to a local SQL Server.
A valid username (if Windows authentication is not being used).
The user password (if required).
If you’re using one of the client applications discussed in the previous lesson, a dialog box will be displayed to prompt you for this information.
After you are connected, you have access to whatever databases and tables your login name has access to. (Logins, access control, and security are revisited in Lesson 29, “Managing Security.”)