SQL Fundamentals Lesson#17 User Access Day 25
SQL Fundamentals Lesson#17 User Access Day 25
Objective:
Use the CREATE USER statement to create and configure a database user, which is an account
through which you can log in to the database, and to establish the means by which Oracle Database
permits access by the user.
You can issue this statement in an Automatic Storage Management cluster to add a user and
password combination to the password file that is local to the ASM instance of the current node. Each
node's ASM instance can use this statement to update its own password file. The password file itself
must have been created by the ORAPWD utility.
You can enable a user to connect to the database through a proxy application or application server.
You must have the CREATE USER system privilege. When you create a user with
the CREATE USER statement, the user's privilege domain is empty. To log on to Oracle Database, a
user must have the CREATE SESSION system privilege. Therefore, after creating a user, you should
grant the user at least the CREATE SESSION system privilege. Refer to GRANT for more
information.
Only a user authenticated AS SYSASM can issue this command to modify the Automatic Storage
Management instance password file.
Page 3 of 10
The BY password clause lets you creates a local user and indicates that the user must specify
password to log on to the database. Passwords are case sensitive. Any subsequent
CONNECT string used to connect this user to the database must specify the password using the
same case (upper, lower, or mixed) that is used in this CREATE USER statement or a subsequent
ALTER USER statement. Passwords can contain any single-byte, multibyte, or special characters, or
any combination of these, from your database character set.
Specify EXTERNALLY to create an external user. Such a user must be authenticated by an external
service, such as an operating system or a third-party service. In this case, Oracle Database relies on
authentication by the operating system or third-party service to ensure that a specific external user
has access to a specific database user.
The GLOBALLY clause lets you create a global user. Such a user must be authorized by the
enterprise directory service (Oracle Internet Directory).
The X.509 name at the enterprise directory service that identifies this user. It should be of the
form CN=username,other_attributes, where other_attributes is the rest of the user's distinguished
name (DN) in the directory. This form creates a private global schema.
A null string (' ') indicating that the enterprise directory service will map authenticated global users
to this database schema with the appropriate roles. This form is the same as specifying
the GLOBALLY keyword alone and creates a shared global schema.
Page 4 of 10
QUOTA Clause
Use the QUOTA clause to specify the maximum amount of space the user can allocate in the
tablespace.
A CREATE USER statement can have multiple QUOTA clauses for multiple tablespaces.
UNLIMITED lets the user allocate space in the tablespace without bound.
Restriction on the QUOTA Clause You cannot specify this clause for a temporary tablespace.
PROFILE Clause
Specify the profile you want to assign to the user. The profile limits the amount of database resources
the user can use. If you omit this clause, then Oracle Database assigns the DEFAULT profile to the
user.
ACCOUNT Clause
Specify ACCOUNT LOCK to lock the user's account and disable access.
Specify ACCOUNT UNLOCK to unlock the user's account and enable access to the account.
Page 5 of 10
Creating a Database User: Example If you create a new user with PASSWORD EXPIRE, then the user's
password must be changed before the user attempts to log in to the database. You can create the
user sidney by issuing the following statement:
Creating External Database Users: Examples The following example creates an external user, who
must be identified by an external source before accessing the database:
To create another user accessible only by an operating system account, prefix the user name with the
value of the initialization parameter OS_AUTHENT_PREFIX. For example, if this value is "ops$", then you
can create the externally identified user external_user with the following statement:
Creating a Global Database User: Example The following example creates a global user. When you
create a global user, you can specify the X.509 name that identifies this user at the enterprise directory
server:
Privileges
• Database security:
– System security
– Data security
• System privileges: Performing a particular action within the database
• Object privileges: Manipulating the content of the database objects
Schemas
A schema is a collection of objects such as tables, views, and sequences. The schema is owned by a
database user and has the same name as that user.
System privileges
Database security can be classified into two categories: system security and data security.
System security covers access and use of the database at the system level, such as the username
and password, the disk space allocated to users, and the system operations that users can perform.
Database security covers access and use of the database objects and the actions that those users
can perform on the objects.
– CREATE SESSION
– CREATE TABLE
– CREATE SEQUENCE
– CREATE VIEW
– CREATE PROCEDURE
Page 8 of 10
Object Privileges
An object privilege is a privilege or right to perform a particular action on a specific table, view,
sequence, or procedure.
Role
A role is a named group of related privileges that can be granted to the user. This method makes it
easier to revoke and maintain privileges.
use for easy management
Page 9 of 10
A privilege that is granted with the WITH GRANT OPTION clause can be passed on to other users
and roles by the grantee.
ROLE_SYS_PRIVS
ROLE_TAB_PRIVS
USER_ROLE_PRIVS
USER_SYS_PRIVS
SYSTEM privilege
select *
from dba_sys_privs
where grantee = 'MILKY';
OBJECT Privileges
select *
from dba_tab_privs
where grantee = 'MILKY';
--ROLE privileges
select *
from dba_role_privs
where grantee = 'MILKY';
• You use the REVOKE statement to revoke privileges granted to other users.
• Privileges granted to others through the WITH GRANT OPTION clause are also revoked.