search
HomeDatabaseMysql TutorialOracle 创建用户及数据表的方法

刚开始学习oracle的朋友可以看下,这个是基础了。

一、概念
1. 数据库 (Database)
什么是数据库?
数据库是依照某种数据模型组织起来并存放二级存储器中的数据集合。这种数据集合具有如下特点:尽可能不重复,以最优方式为某个特定组织的多种应用服务,其数据结构独立于使用它的应用程序,对数据的增、删、改和检索由统一软件进行管理和控制。从发展的历史看,数据库是数据管理的高级阶段,它是由文件管理系统发展起来的。
什么是数据库系统?
数据库系统是一个实际可运行的存储、维护和应用系统提供数据的软件系统,是存储介质、处理对象和管理系统的集合体。它通常由软件、数据库和数据管理员组成。其软件主要包括操作系统、各种宿主语言、实用程序以及数据库管理系统。数据库由数据库管理系统统一管理,数据的插入、修改和检索均要通过数据库管理系统进行。数据管理员负责创建、监控和维护整个数据库,使数据能被任何有权使用的人有效使用。数据库管理员一般是由业务水平较高、资历较深的人员担任

打个比喻吧:库据库就是存放数据的仓库. 当然仓库得组织得有序,这需要一套管理方法及管理组织,管理方法及管理组织结合就成了一个管理仓库的有机体 -- 系统.
2. 数据表空间 (Tablespace)
存放数据总是需要空间, Oracle把一个数据库按功能划分若干空间来保存数据。当然数据存放在磁盘最终是以文件形式,所以一盘一个数据表空间包含一个以上的物理文件
3. Oracle用户
一个数据库多个用户来创建和管理自己的数据, 每个用户有自己的权限,也可与其他用户共享数据
4. 数据表
在仓库,我们可能有多间房子,每个房子又有多个货架,每架又有多层。 我们在数据库中存放数据,最终是数据表的单元来存储与管理的。
5. 数据文件
以上几个概念都是逻辑上的, 而数据文件则是物理上的。就是说,数据文件是真正“看得着的东西”,它在磁盘上以一个真实的文件体现.

二、创建
(*凡oracle命令在 sqlplus中执行, 即运行 sqlplusw system/manager@test -这是以前安装时讲到的)
1. 数据库 当我们安装好oracle8i后,一个数据库系统就安装好了,其中有一个缺省的数据库,当然,我们还可以创建新的数据库.
2. 现在我们应该建数据表空间, 就如要存放货物,起码首先得把房子建好吧。就是存放东西的空间。表空间就存放数据的空间.
格式: create tablespace 表间名 datafile '数据文件名' size 表空间大小;
example:
create tablespace data_test datafile 'e:\oracle\oradata\test\data_1.dbf' size 2000M;
create tablespace idx_test datafile 'e:\oracle\oradata\test\idx_1.dbf' size 2000M;
(*数据文件名 包含全路径, 表空间大小 2000M 表是 2000兆)
3. 建好 tablespace, 就可以建用户了
格式: create user 用户名 identified by 密码 default tablespace 表空间表;
example:
create user study identified by study default tablespace data_test;
(*我们创建一个用户名为 study,密码为 study, 缺少表空间为 data_test -这是在第二步建好的.)
(*抽省表空间表示 用户study今后的数据如果没有专门指出,其数据就保存在 data_test中, 也就是保存在对应的物理文件 e:\oracle\oradata\test\data_1.dbf中)
4. 授权给新用户
grant connect,resource to study;
--表示把 connect,resource权限授予study用户
grant dba to study;
--表示把 dba权限授予给 study
5. 创建数据表
在上面,我们已建好了用户 study 我们现在进入该用户
sqlplusw study/study@test
然后就可以在用户study中创建数据表了
格式: create table 数据表名 , 后面的详细参数,请你在网上搜索 "oracle" "create table" "语法". 太多了,我就不附在这里了。
下面给一个例子,自己体会.
create table test_user (
no number(5) not null , --pk
username varchar2(30) not null , --用户名
passpord varchar2(30) not null , --密码
constraint pk_connectdb primary key(no)
)storage (initial 10k next 10k pctincrease 0);
*下面讲解上面命令的各方面的含义
create table test_user --创建数据表
no number(5) not null , --pk
(列名或字段名) 数据类型(数据长度) 该数据列不能为空 ,是列之间的分隔符 --后的内容是注释
constraint pk_connectdb primary key(no)
(约束) 约束名 (主键) (列名) 意思就是 在数据表 test_user中所有行数据 no的值不能相同(这就是主键的含义)
storage (initial 10k next 10k pctincrease 0); 这个说起来比较复杂, 反正如果某个数据表要存放大量数据,就把initial和next后的值设置大一点, 否则设置小一点.
既然上面在创建数据表中没有特别指定 表空间,当然该表就存放在study缺省表空间data_test了.
create tablespace data_phonepos datefile 'd:\install\OracleXpdb\datafilephonepos.dbf' size 8000M;
create user phonepos identified by phonepos default tablespace data_phonepos;
grant connect, resource to phonepos;
grant dba to phonepos;

权限的查询
5。1 查询某个用户授予其他用户在当前用户模式下的对象权限
select * from user_tab_privs_made --假如当前用户为WENZI,那么查询结果就是由WENZI授权,在WENZI模式下的权限记录
5。2 查询某个用户授予其他用户在该用户模式对象及其他模式对象上的对象权限
select * from all_tab_privs_made -- 假如当前登录用户为WENZI,那么查询结果就是所有由WENZI授予的权限的记录

修改用户
ALTER USER avyrros
IDENTIFIED EXTERNALLY
DEFAULT TABLESPACE data_ts
TEMPORARY TABLESPACE temp_ts
QUOTA 100M ON data_ts
QUOTA 0 ON test_ts
PROFILE clerk;
删除用户
DROP USER username [CASCADE] --CASECADE 选项会删除该用户模式下的所有对象,建议在删除前,先确认是否有其他的依赖关系存在。
查询属于用户的对象
select owner,object_name,object_type,status from dba_objects where owner='WENZI'
5.3 查询为某个用户授予的,在其他模式对象上的权限
select * from user_tab_privs_recd --假如当前登录用户为WENZI,那么查询结果就是WENZI在其他模式对象上的权限
5.4 查询为某个用户授予的,在该用户模式对象与其他模式对象上的权限
select * from all_tab_privs_recd --假如当前用户为wenzi,则查询结果为wenzi在整个数据库中拥有权限的对象

角色管理
创建口令文件
orapwd file='..........\pwd{SID}.ora' password='***(sys的密码)' tntries=10(口令文件最大的用户数量)
要使某个用户可以使用口令文件,必须为其授予SYSDBA权限,系统会自动将其加入到口令文件中。
grant sysdba to wenzi
当收回SYSDBA权限时,系统将对应的用户从口令文件中删除。
revoke sysdba from wenzi
查看口令文件管理的用户
select * from v$pwfile_users
Statement
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
What are stored procedures in MySQL?What are stored procedures in MySQL?May 01, 2025 am 12:27 AM

Stored procedures are precompiled SQL statements in MySQL for improving performance and simplifying complex operations. 1. Improve performance: After the first compilation, subsequent calls do not need to be recompiled. 2. Improve security: Restrict data table access through permission control. 3. Simplify complex operations: combine multiple SQL statements to simplify application layer logic.

How does query caching work in MySQL?How does query caching work in MySQL?May 01, 2025 am 12:26 AM

The working principle of MySQL query cache is to store the results of SELECT query, and when the same query is executed again, the cached results are directly returned. 1) Query cache improves database reading performance and finds cached results through hash values. 2) Simple configuration, set query_cache_type and query_cache_size in MySQL configuration file. 3) Use the SQL_NO_CACHE keyword to disable the cache of specific queries. 4) In high-frequency update environments, query cache may cause performance bottlenecks and needs to be optimized for use through monitoring and adjustment of parameters.

What are the advantages of using MySQL over other relational databases?What are the advantages of using MySQL over other relational databases?May 01, 2025 am 12:18 AM

The reasons why MySQL is widely used in various projects include: 1. High performance and scalability, supporting multiple storage engines; 2. Easy to use and maintain, simple configuration and rich tools; 3. Rich ecosystem, attracting a large number of community and third-party tool support; 4. Cross-platform support, suitable for multiple operating systems.

How do you handle database upgrades in MySQL?How do you handle database upgrades in MySQL?Apr 30, 2025 am 12:28 AM

The steps for upgrading MySQL database include: 1. Backup the database, 2. Stop the current MySQL service, 3. Install the new version of MySQL, 4. Start the new version of MySQL service, 5. Recover the database. Compatibility issues are required during the upgrade process, and advanced tools such as PerconaToolkit can be used for testing and optimization.

What are the different backup strategies you can use for MySQL?What are the different backup strategies you can use for MySQL?Apr 30, 2025 am 12:28 AM

MySQL backup policies include logical backup, physical backup, incremental backup, replication-based backup, and cloud backup. 1. Logical backup uses mysqldump to export database structure and data, which is suitable for small databases and version migrations. 2. Physical backups are fast and comprehensive by copying data files, but require database consistency. 3. Incremental backup uses binary logging to record changes, which is suitable for large databases. 4. Replication-based backup reduces the impact on the production system by backing up from the server. 5. Cloud backups such as AmazonRDS provide automation solutions, but costs and control need to be considered. When selecting a policy, database size, downtime tolerance, recovery time, and recovery point goals should be considered.

What is MySQL clustering?What is MySQL clustering?Apr 30, 2025 am 12:28 AM

MySQLclusteringenhancesdatabaserobustnessandscalabilitybydistributingdataacrossmultiplenodes.ItusestheNDBenginefordatareplicationandfaulttolerance,ensuringhighavailability.Setupinvolvesconfiguringmanagement,data,andSQLnodes,withcarefulmonitoringandpe

How do you optimize database schema design for performance in MySQL?How do you optimize database schema design for performance in MySQL?Apr 30, 2025 am 12:27 AM

Optimizing database schema design in MySQL can improve performance through the following steps: 1. Index optimization: Create indexes on common query columns, balancing the overhead of query and inserting updates. 2. Table structure optimization: Reduce data redundancy through normalization or anti-normalization and improve access efficiency. 3. Data type selection: Use appropriate data types, such as INT instead of VARCHAR, to reduce storage space. 4. Partitioning and sub-table: For large data volumes, use partitioning and sub-table to disperse data to improve query and maintenance efficiency.

How can you optimize MySQL performance?How can you optimize MySQL performance?Apr 30, 2025 am 12:26 AM

TooptimizeMySQLperformance,followthesesteps:1)Implementproperindexingtospeedupqueries,2)UseEXPLAINtoanalyzeandoptimizequeryperformance,3)Adjustserverconfigurationsettingslikeinnodb_buffer_pool_sizeandmax_connections,4)Usepartitioningforlargetablestoi

See all articles

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

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools