20.07.2013 Views

Beginning SQL

Beginning SQL

Beginning SQL

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 12<br />

3. In the <strong>SQL</strong> window, type in this command:<br />

USE FilmClub<br />

This tells <strong>SQL</strong> Server that the commands to follow are to be used in the Film Club database. This<br />

syntax is useful only for users of <strong>SQL</strong> Server, and the details of the syntax can be found in Books<br />

Online.<br />

4. The sp_addlogin stored procedure creates a new Microsoft <strong>SQL</strong> Server login that allows a user<br />

to connect to an instance of <strong>SQL</strong> Server using <strong>SQL</strong> Server authentication. It does not give permissions<br />

for that user to do anything.<br />

sp_addlogin [ @loginame = ] ‘login’<br />

[ , [ @passwd = ] ‘password’ ]<br />

[ , [ @defdb = ] ‘database’ ]<br />

[ , [ @deflanguage = ] ‘language’ ]<br />

[ , [ @sid = ] sid ]<br />

[ , [ @encryptopt = ] ‘encryption_option’ ]<br />

5. In the <strong>SQL</strong> window, type the following:<br />

EXECUTE sp_addlogin @loginame = ‘John’, @passwd = ‘ASDFG’<br />

EXECUTE sp_addlogin @loginame = ‘Joe’, @passwd = ‘qwerty’<br />

EXECUTE sp_addlogin @loginame = ‘Lynn’, @passwd = ‘zxcvbn’<br />

EXECUTE sp_addlogin @loginame = ‘Fred’, @passwd = ‘mnbvc’<br />

EXECUTE sp_addlogin @loginame = ‘Amy’, @passwd = ‘lkjhg’<br />

EXECUTE sp_addlogin @loginame = ‘Beth’, @passwd = ‘poiuy’<br />

EXECUTE sp_adduser ‘John’, ‘John’<br />

EXECUTE sp_adduser ‘Joe’, ‘Joe’<br />

EXECUTE sp_adduser ‘Lynn’, ‘Lynn’<br />

EXECUTE sp_adduser ‘Fred’, ‘Fred’<br />

EXECUTE sp_adduser ‘Amy’, ‘Amy’<br />

EXECUTE sp_adduser ‘Beth’, ‘Beth’<br />

How It Works<br />

The sp_addlogin stored procedure simply adds a new user to the <strong>SQL</strong> Server login system, allowing a<br />

user to log in to <strong>SQL</strong> Server using a specific username and password. After executing these two statements,<br />

a user can log in using the name John and the password ASDFG or the name Joe and the password<br />

qwerty.<br />

Group IDs (Roles)<br />

332<br />

Given a large database with hundreds or thousands of users, administration of user privileges becomes<br />

extremely complex and unwieldy. If every user has to be assigned every privilege they need, the process<br />

soon becomes unmanageable. In order to deal with this problem, the concept of groups or roles has evolved.<br />

Groups or roles build on the idea of users, when more than one user needs the same privileges to the<br />

same objects. Users in Accounting need access to salary information for all employees, while users in<br />

Manufacturing need access to inventory data. In order to provide this logical grouping, group IDs are<br />

created and privileges are then granted to the group. A group can access tables and columns of tables,<br />

add records, and so forth. Once the group is defined and the privileges assigned, users are added to<br />

the group.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!