当前位置:Gxlcms > 数据库问题 > Oracle1

Oracle1

时间:2021-07-01 10:21:17 帮助过:4人阅读

技术分享图片

数据库结构(重点)

       默认用户:

      scott:普通用户,是Oracle一个示范用户,主要用于用户学习

      System:普通用户,但授予了DBA角色

      Sys:管理员用户,具有Oracle服务器中最高权限

创建用户的语法:

create user yx identified by 123456;

删除用户:(cascade表示连同该用户的所有对象全部级联删除,如果在用户下有数据库对象,必须使用cascade)

drop user yx cascade;

修改密码:(新密码为123456)

alter user identified by 123456;

给用户授权:

grant dba to yx; 给用户授予管理员权限

grant connetion to yx; 允许用户连接数据库,并创建数据库对象

grant resource to yx; 允许用户使用数据库中的存储空间

grant create sequence to yx; 允许用户在当前模式中创建序列,此权限包含在connection角色中

grant select on scott.emp to yx;  允许用户查询scott.emp表的记录

grant update on scott.emp to yx;允许用户更新scott.emp表的数据

grant all on scott.emp to yx; 允许用户更新,查询,删除,插入表的记录

撤销授予的权限(revoke)

revoke all on scott.emp  from yx; 撤销用户可以查询,插入scott.emp等中记录

revoke update on scott.emp from yx; 撤销用户可以更新scott.emp表数据的权限

创建表空间(表都存储在表空间中,利于对表空间授予权限)

create tablespace yuxi_space()

创建表区(表名:customer)

Create table customer(

   stu_id   number(4,0) , 小数位最多0位,整数位最多4位

   stu_name   varchar2(8) , 姓名的字符最多为8,小于8的时候自动变短

   stu_sex   varchar(4) ,性别的字符为4个字节

   stu_card   number(8),

   birthday   date

);

表中的权限

alter table customer add constraint pk_id primary   key(stu_id) –主健约束

alter table customer add constraint pk_sex check(stu_sex=’男’ or stu_sex=’女’)—检查约束

Alter table customer modify(stu_name not null) --非空约束

Alter table customer modify birthday default sysdate--默认约束

Alter table customer add constriant up_card unique(stu_card)唯一约束

创建表的同时,给表赋予权限(当表中的权限不发生重复)

Create table student(

   Stu_id number(6) primary key,

Stu_name   varchar2(8) not null,

Stu_sex   varchar(4) check(stu_sex=’男’ or stu_sex=’女’),

Stu_card   number(8) unique(stu_card),

Birthday   date default sysdate

);

对表的一些修改操作

删除表(表名student)

Drop table student();

重命名表(将表名customer换成cus)

Rename table cus to customer;

增加字段

Alter table student add(stu_card char(18));

删除字段(删除stu_birth行)

Alter table student drop column stu_birth;

数据库结构(重点)

                       

默认用户:

      scott:普通用户,是Oracle一个示范用户,主要用于用户学习

      System:普通用户,但授予了DBA角色

      Sys:管理员用户,具有Oracle服务器中最高权限

创建用户的语法:

create user yx identified by 123456;

删除用户:(cascade表示连同该用户的所有对象全部级联删除,如果在用户下有数据库对象,必须使用cascade)

drop user yx cascade;

修改密码:

alter user identified by 123456;

给用户授权:

grant dba to yx; 给用户授予管理员权限

grant connetion to yx; 允许用户连接数据库,并创建数据库对象

grant resource to yx; 允许用户使用数据库中的存储空间

grant create sequence to yx; 允许用户在当前模式中创建序列,此权限包含在connection角色中

grant select on scott.emp to yx;  允许用户查询scott.emp表的记录

grant update on scott.emp to yx;允许用户更新scott.emp表的数据

grant all on scott.emp to yx; 允许用户更新,查询,删除,插入表的记录

撤销授予的权限

revoke all on scott.emp  from yx; 撤销用户可以查询,插入scott.emp等中记录

revoke update on scott.emp from yx; 撤销用户可以更新scott.emp表数据的权限

创建表空间(表都存储在表空间中,利于对表空间授予权限)

create tablespace yuxi_space()

创建表区(表名:customer)

Create table customer(

   stu_id   number(4,0) , 小数位最多0位,整数位最多4位

   stu_name   varchar2(8) , 姓名的字符最多为8,小于8的时候自动变短

   stu_sex   varchar(4) ,性别的字符为4个字节

   stu_card   number(8),

   birthday   date

);

表中的权限

alter table customer add constraint pk_id primary   key(stu_id) –主健约束

alter table customer add constraint pk_sex check(stu_sex=’男’ or stu_sex=’女’)—检查约束

Alter table customer modify(stu_name not null) --非空约束

Alter table customer modify birthday default sysdate--默认约束

Alter table customer add constriant up_card unique(stu_card)唯一约束

创建表的同时,给表赋予权限(当表中的权限不发生重复)

Create table student(

   Stu_id number(6) primary key,

Stu_name   varchar2(8) not null,

Stu_sex   varchar(4) check(stu_sex=’男’ or stu_sex=’女’),

Stu_card   number(8) unique(stu_card),

Birthday   date default sysdate

);

对表的一些修改操作

删除表(表名student)

Drop table student();

重命名表(将表名customer换成cus)

Rename table cus to customer;

增加字段

Alter table student add(stu_card char(18));

删除字段(删除stu_birth行)

Alter table student drop column stu_birth;

修改列的长度

Alter table customer modify stu_name varchar(10);

增加数据

Insert into customer values(3,’john’,’男’,default);

Insert into customer(stu_id,stu_name) values(2,’paul’);

Insert into customer values(4,’susan’,’女’,’1-3月-2017’); --日期

Insert into customer values(4,’susan’,’女’,to_date(‘2089-2-2’,’yyyy-MM-dd’));   --日期

删除数据

Delete Student where stu_id=5;

Delete student where stu_id=4 and stu_name=’susan’;

修改数据

Update student set stu_name=’yx’ where stu_id=’3’;

改列的长度

Alter table customer modify stu_name varchar(10);

增加数据

Insert into customer values(3,’john’,’男’,default);

Insert into customer(stu_id,stu_name) values(2,’paul’);

Insert into customer values(4,’susan’,’女’,’1-3月-2017’); --日期

Insert into customer values(4,’susan’,’女’,to_date(‘2089-2-2’,’yyyy-MM-dd’));   --日期

删除数据

Delete Student where stu_id=5;

Delete student where stu_id=4 and stu_name=’susan’;

修改数据

Update student set stu_name=’yx’ where stu_id=’3’;

Oracle1

标签:alter   img   整数   int   select   system   创建序列   增加   删除表   

人气教程排行