本文共 2170 字,大约阅读时间需要 7 分钟。
数据库管理员可以通过以下命令创建新的数据库用户:
create user 用户名 identified by 密码 default tablespace users temporary tablespace temp quota users on users;
需要注意以下几点:
users
作为用户的默认表空间。temp
。为了提升用户权限,可以执行以下操作:
grant resource, connect to 用户名;grant dba to 用户名;
这一步确保用户可以访问数据库资源并管理其他用户。
撤回权限使用revoke
命令:
revoke <权限1> , <权限2> from 用户名; 权限2> 权限1>
需要明确说明要撤回的权限类型。
删除用户时必须使用dba
访问权限:
drop user 用户名; -- 不会删除用户的相关对象drop user 用户名 cascade; -- 会删除用户及其所有相关对象
请注意,删除用户之前确保其下没有依赖对象。
锁定用户账号:
create profile lock_account limit failed_login_attempts 3 password_lock_time 2;
可以通过以下命令修改或解锁:
alter user 用户名 profile lock_account;alter user 用户名 account unlock;
为强制用户定期更改密码:
create profile myprofile limit password_life_time 10 password_grace_time 2;alter user 用户名 profile myprofile;
drop profile profile文件名;
常用数据类型及说明:
char(size)
和varchar(size)
:定长或变长字符串nchar(size)
和nvarchar2
:Unicode编码存储的定长或变长字符串number(p,s)
:指定精度和刻度的数值类型float
:浮点数(近似值)int
、smallint
、real
、double
:不同精度的数值类型date
:日期类型timestamp
:时间戳(精确到毫秒)blob
和clob
:二进制对象nclob
:Unicode编码字符对象类型 | 描述 |
---|---|
DDL | 数据定义语言(创建、更改、删除对象) |
DML | 数据操纵语言(操作数据) |
DCL | 数据控制语言(权限管理) |
create table 表名( 字段名 类型);
或使用自定义:
create table 表名( 字段名 varchar(10));
create global temporary table 表名( 字段名 类型);
使用describe
命令:
describe 表名;
rename 旧表名 to 新表名;
comment on table 表名 is '备注';
针对列也可以加注释:
comment on column 列名 is '备注';
select * from user_tab_comments;select * from user_col_comments;
全量复制:
create table 表名 as select * from 源表名;
仅复制结构:
create table 表名 as select * from 源表名 where 1 = 2;
或通过插入具体字段:
insert into 表名 (id,name,sal,job,deptno) select empno,ename,sal,job,deptno from emp;
###.addColumn、修改列和删除列
alter table 表名 add (新列名 类型);alter table 表名 modify (列名 类型);alter table 表名 drop (列名);
insert into 表名 (列名1,列名2) values (value1 ,value2);
注意:字符串和日期型需用单引号包围,且值与字段类型匹配。如插入空值:
insert into student(xh,xm,sex,birthday) values (‘A004’,‘MARTIN’,‘男’,null);
update 表名 set 列名 = 新值 where 列名 = 某值;
全表删除:
delete from 表名; -- 可恢复
删除表:
drop table 表名; -- 删除表和数据truncate table 表名; -- 只删除数据,表结构保留
使用dba
身份执行严重操作,确保用户具有drop user
权限。
通过以上步骤,数据库管理员可以有效地管理数据库用户和表结构,确保数据库的安全性和高效运行。
转载地址:http://cyzpz.baihongyu.com/