Home Database Mysql Tutorial Oracle新建用户、角色,授权,建表空间的sql语句

Oracle新建用户、角色,授权,建表空间的sql语句

Jun 07, 2016 pm 06:07 PM
Authorize Role

Oracle创建用户操作相信大家都不陌生,下面就为您介绍Oracle创建用户的语法的相关知识,希望对您学习Oracle创建用户的方面能有所帮助

oracle数据库的权限系统分为系统权限与对象权限。系统权限( database system privilege )可以让用户执行特定的命令集。例如,create table权限允许用户创建表,grant any privilege 权限允许用户授予任何系统权限。对象权限( database object privilege )可以让用户能够对各个对象进行某些操作。例如delete权限允许用户删除表或视图的行,select权限允许用户通过select从表、视图、序列(sequences)或快照(snapshots)中查询信息。

  每个oracle用户都有一个名字和口令,并拥有一些由其创建的表、视图和其他资源。oracle角色(role)就是一组权限(privilege)(或者是每个用户根据其状态和条件所需的访问类型)。用户可以给角色授予或赋予指定的权限,然后将角色赋给相应的用户。一个用户也可以直接给其他用户授权。

一、创建用户

Oracle创建用户的语法:

Oracle创建用户(密码验证用户),可以采用CREATE USER命令。

CREATE USER username IDENTIFIED BY password

OR IDENTIFIED EXETERNALLY

OR IDENTIFIED GLOBALLY AS ‘CN=user'

[DEFAULT TABLESPACE tablespace]

[TEMPORARY TABLESPACE temptablespace]

[QUOTA [integer K[M] ] [UNLIMITED] ] ON tablespace

[,QUOTA [integer K[M] ] [UNLIMITED] ] ON tablespace

[PROFILES profile_name]

[PASSWORD EXPIRE]

[ACCOUNT LOCK or ACCOUNT UNLOCK]

其中,

CREATE USER username:用户名,一般为字母数字型和“#”及“_”符号。

IDENTIFIED BY password:用户口令,一般为字母数字型和“#”及“_”符号。

IDENTIFIED EXETERNALLY:表示用户名在操作系统下验证,该用户名必须与操作系统中所定义的用户名相同。

IDENTIFIED GLOBALLY AS ‘CN=user':用户名由Oracle安全域中心服务器验证,CN名字表示用户的外部名。

[DEFAULT TABLESPACE tablespace]:默认的表空间。

[TEMPORARY TABLESPACE tablespace]:默认的临时表空间。

[QUOTA [integer K[M] ] [UNLIMITED] ] ON tablespace:用户可以使用的表空间的字节数。

[PROFILES profile_name]:资源文件的名称。

[PASSWORD EXPIRE]:立即将口令设成过期状态,用户再登录前必须修改口令。

[ACCOUNT LOCK or ACCOUNT UNLOCK]:用户是否被加锁,默认情况下是不加锁的。

  oracle内部有两个建好的用户:system和sys。用户可直接登录到system用户以创建其他用户,因为system具有创建别 的用户的 权限。 在安装oracle时,用户或系统管理员首先可以为自己建立一个用户。例 如 :

代码如下:
create user user01 identified by u01;

  该命令还可以用来设置其他权限,详细情况参见自学资料。要改变一个口令,可以使用alter user命令:
代码如下:
alter user user01 identified by usr01;

现在user01的口令已由“u01”改为“usr01”。

  除了alter user命令以外,用户还可以使用password命令。如果使用password命令,用户输入的新口令将不在屏幕上显示。有dba特权的用户可以通过password命令改变任何其他用户的口令;其他用户只能改变自己的口令。

  当用户输入password命令时,系统将提示用户输入旧口令和新口令,如下所示:

  password
  changing password for user01
  old password:
  new password:
  retype new password:

  当成功地修改了口令时,用户会得到如下的反馈:

  password changed

二 、删除用户

  删除用户,可以使用drop user命令,如下所示:
代码如下:
  drop user user01;

  如果用户拥有对象,则不能直接删除,否则将返回一个错误值。指定关键字cascade,可删除用户所有的对象,然后再删除用户。下面的例子用来删除用户与其对象:
代码如下:
  drop user user01 cascade;


三 、3种标准角色

  qracle为了兼容以前的版本,提供了三种标准的角色(role):connect、resource和dba。

  1. connect role(连接角色)

  临时用户,特别是那些不需要建表的用户,通常只赋予他们connectrole。connect是使用oracle的简单权限,这种权限只有在对其他用户的表有访问权时,包括select、insert、update和delete等,才会变得有意义。拥有connect role的用户还能够创建表、视图、序列(sequence)、簇(cluster)、同义词(synonym )、会话(session)和与其他数据库的链(link)。

  2. resource role(资源角色)

  更可靠和正式的数据库用户可以授予resource role。resource提供给用户另外的权限以创建他们自己的表、序列、过程(procedure)、触发器(trigger)、索引(index)和簇(cluster)。

  3. dba role(数据库管理员角色)

  dba role拥有所有的系统权限----包括无限制的空间限额和给其他用户授予各种权限的能力。system由dba用户拥有。下面介绍一些dba经常使用的典型权限。

  (1)grant(授权)命令

  下面对刚才创建的用户user01授权,命令如下:

  grant connect, resource to user01;

  (2)revoke(撤消)权限

  已授予的权限可以撤消。例如撤消(1)中的授权,命令如下:
代码如下:
  revoke connect, resource from user01;

  一个具有dba角色的用户可以撤消任何别的用户甚至别的dba的connect、resource 和dba的其他权限。当然,这样是很危险的,因此,除非真正需要,dba权限不应随便授予那些不是很重要的一般用户。 撤消一个用户的所有权限,并不意味着从oracle中删除了这个用户, 也不会破坏用户创建的任何表;只是简单禁止其对这些表的访问。其他要访问这些表的用户可以象以前那样地访问这些表。

四、创建角色

  除了前面讲到的三种系统角色----connect、resource和dba,用户还可以在oracle创建自己的role。用户创建的role可以由表或系统权限或两者的组合构成。为了创建role,用户必须具有create role系统权限。下面给出一个create role命令的实例:
代码如下:
  create role student;

  这条命令创建了一个名为student的role。

  一旦创建了一个role,用户就可以给他授权。给role授权的grant命令的语法与对对用户的语法相同。在给role授权时,在grant命令的to子句中要使用role的名称,如下所示:
代码如下:
  grant select on class to student;

  现在,拥有student 角色的所有用户都具有对class 表的select权限。

五、删除角色

  要删除角色,可以使用drop role命令,如下所示:
代码如下:
  drop role student;

  指定的role连同与之相关的权限将从数据库中全部删除。

六、删除表的注意事项

在删除一个表中的全部数据时,须使用

Sql代码
代码如下:
truncate table 表名

因为用drop table,delete * from 表名时,tablespace表空间该表的占用空间并未释放,反复几次drop,delete操作后,该tablespace上百兆的空间就被耗光了。
作者“技术总结”
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How many characters are there in Blazlan Chaos Effect? How many characters are there in Blazlan Chaos Effect? Mar 21, 2024 pm 10:56 PM

Blue Wings Chaos Effect features a diverse cast of characters, each with a unique identity and backstory. For this reason, the editor has specially compiled an introduction to the characters of BlazBlue Chaos Effect for all players. How many characters are there in BlazBlue Chaos Effect? ​​Answer: There are 7 characters. 1. [God of Death] Ragnar Chad Bradedge (nicknamed RG, Nissan), his brother and sister were raised by church nuns. One day, one of the six heroes of the villain broke in, killed the nuns, and burned them down. Church, took his sister away, leaving behind his younger brother "The Weapon of Things" Ice Sword Snow Girl. 2. Noel Vermillion The adopted daughter of the Vermillion family looks almost the same as Ragnar's sister. After graduation, he joined the governing body as secretary to Ragnar's younger brother. 3. λ-11 is collectively known as Lambda and Eleventh Sister. After the original developer gave up, Kokonoe rescued and

The best alternative to CrushOn.AI that offers unlimited free messages The best alternative to CrushOn.AI that offers unlimited free messages Mar 06, 2024 pm 12:10 PM

In this article we will introduce you to the best alternatives to CrushOn.AI with free and unlimited messaging capabilities. There are many artificial intelligence platforms on the market now that allow users to talk to characters from various media such as animation, which provides users with a more interesting and interactive experience. What is CrushOn.AI? CrushonAI is an AI chatbot platform that allows users to experience the fun of interaction by having conversations with virtual characters. Users have the opportunity to communicate with, build connections with, and create storylines related to their favorite characters across a variety of media including anime. The best alternative to CrushOn.AI that offers unlimited free messages If you are looking for the best Crush

How to upgrade win10 enterprise version 2016 long-term service version to professional version How to upgrade win10 enterprise version 2016 long-term service version to professional version Jan 03, 2024 pm 11:26 PM

When we no longer want to continue using the current Win10 Enterprise Edition 2016 Long-Term Service Edition, we can choose to switch to the Professional Edition. The method is also very simple. We only need to change some contents and install the system image. How to change win10 enterprise version 2016 long-term service version to professional version 1. Press win+R, and then enter "regedit" 2. Paste the following path directly in the address bar above: Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\CurrentVersion3 , then find the EditionID and replace the content with "professional" to confirm

Anchor Point Advent Novice Ten Company Character Recommendations Anchor Point Advent Novice Ten Company Character Recommendations Feb 20, 2024 pm 02:30 PM

Anchor Arrival is a 3D turn-based card game with a high-definition beautiful girl two-dimensional theme. It provides a rich and exciting combination of characters for players to explore and experience. It has many powerful combinations of high-quality lineups. New players are also curious novices. What powerful characters are recommended in the pool? Let’s take a look at the selection reference for novices to win ten consecutive golds! Anchor Point Advent is a powerful character recommendation for novice pools. The first ten-consecutive pick is Alice. She is mainly a single-target lightning-type burst character. The output is very explosive, and the experience will be very friendly to newcomers, so it is highly recommended to choose it. It is recommended to choose the combination of "Alice" + "Antelope" for 10 points. Alice is the most worthy character to output the goldpire attribute, and is not even a bit stronger than the other two characters in the novice card pool. Alice can pass special

How to implement role permission management system in PHP? How to implement role permission management system in PHP? Jun 29, 2023 pm 07:57 PM

PHP is a widely used programming language that is widely used to create and develop various web applications. In many web applications, the role permission management system is an important feature to ensure that different users have appropriate access rights. This article will introduce how to use PHP to implement a simple and practical role permission management system. The basic concept of the role permission management system is to divide users into different roles and assign corresponding permissions to each role. In this way, users can only perform operations they have permission to perform, thus ensuring the system's

How to use Flask-Security to implement user authentication and authorization How to use Flask-Security to implement user authentication and authorization Aug 04, 2023 pm 02:40 PM

How to use Flask-Security to implement user authentication and authorization Introduction: In modern web applications, user authentication and authorization are essential functions. To simplify this process, Flask-Security is a very useful extension that provides a series of tools and functions to make user authentication and authorization simple and convenient. This article will introduce how to use Flask-Security to implement user authentication and authorization. 1. Install the Flask-Security extension: at the beginning

UniApp implements detailed analysis of user login and authorization UniApp implements detailed analysis of user login and authorization Jul 05, 2023 pm 11:54 PM

UniApp implements detailed analysis of user login and authorization. In modern mobile application development, user login and authorization are essential functions. As a cross-platform development framework, UniApp provides a convenient way to implement user login and authorization. This article will explore the details of user login and authorization in UniApp, and attach corresponding code examples. 1. Implementation of user login function Create login page User login function usually requires a login page, which contains a form for users to enter their account number and password and a login button

How to get authorization for Douyin slices and goods? Is Douyin slicing easy to make? How to get authorization for Douyin slices and goods? Is Douyin slicing easy to make? Mar 07, 2024 pm 10:52 PM

Douyin, as a popular social media platform at the moment, not only provides people with a wealth of entertainment content, but has also become an important channel for many brands and merchants to promote products and achieve sales. Among them, Douyin’s slicing and selling products has become a novel and efficient marketing method. So, how do you get authorization for Douyin's sliced ​​products? 1. How do you get authorization for Douyin's sliced ​​products? Douyin's sliced ​​products decompose long videos into short video clips and embed product promotion information in them to attract viewers to buy. . When slicing and selling goods on Douyin, the first step is to obtain authorization from the original video. When looking for a suitable licensor, you can consider using various channels such as Douyin platform, social media and industry forums. Find creators or copyright holders with popular video content and actively connect with them,

See all articles