one:
sys superuser
system
scott/tiger
===============================================
in cmd
1. Log in with sys;
sqlplus sys/1234@myoracle as sysdba
--Query the current instance name
select instance_name from v$instance;
--Query the current database name
select name from v$database;
2. If the scott/tiger user is locked;
alter user scott account unlock;//Unlock unlock, lock lock
conn scott/tiger; //The password modification box pops up, and you can change the scott password
======
Forgot the password, modify the sys and system user passwords :
----Enter sqlplus for password reset----
sqlplus/as sysdba
null
alter user sys identified by 1234; //Change the password of sys to 1234
conn sys/1234 as sysdba; //Switch to sys
alter user system identified by 1234;//Change the passwords of other accounts in this way
===============================================
1. View all usernames
select username from dba_users;
2. Delete the user and the table under the user
drop user username cascade;
3. Find out the user's session:
SELECT SID, SERIAL# FROM V$SESSION WHERE USERNAME='SCOTT';
4. Kill the session of user SCOTT:
ALTER SYSTEM KILL SESSION 'SID, SERIAL#';
5.查看当前登录数据库的用户:
SELECT * FROM V$SESSION WHERE TYPE='USER';
6.查看所有用户信息
SELECT * FROM DBA_USERS
7.有时候需要导出某用户下的所有table、view、sequence、trigger等信息,下面的SQL可以将这些信息select出来:
select * from user_tables;
select * from user_views;
select * from user_sequences;
select * from user_triggers;
8.查看当前用户的默认表空间
SQL>select username,default_tablespace from user_users;
9.查看当前用户的角色
SQL>select * from user_role_privs;
10.查看当前用户的系统权限和表级权限
SQL>select * from user_sys_privs;
SQL>select * from user_tab_privs;
11.显示当前会话所具有的权限
SQL>select * from session_privs;
显示指定用户所具有的系统权限
SQL>select * from dba_sys_privs where grantee=’GAME’;
===============================================
二:
表空间
查看表空间
select * form v$tablespace;
查看表空间详细的数据文件
select file_name,tablespace_name from dba_data_files;
创建表空间(创建表空间的时候,指定多个数据文件,以逗号隔开:)
create tablespace 表空间名 datafile '路径+数据文件名1.dbf' size 50m
autoextend on next 10m maxsize unlimited;//数据文件自动扩容,开启自动扩展,一次扩展10m,表空间最大的大小是无限大
查看表空间是否为自动扩展
select tablespace_name,autoextensible from dba_data_files;
alter database datafile '路径+数据文件名' autoextend off;//取消自动扩展
alter database datafile '路径+数据文件名' autoextend on;//开启自动扩展
增加数据文件2
alter tablespace 表空间名 add datafile '路径+数据文件2.dbf' size 50m;
删除表空间,没有删除内部文件
drop tablespace 表空间名;
删除表空间,同时删除内部文件
drop tablespace 表空间名 including contants and datafiles;
===============================================
简化权限管理,引入了角色的概念,角色是具有名称的一组权限的组合
------常用系统预定义角色
1.CONNECT:临时用户
2.RESOURCE:更为可靠和正式的用户
3.DBA:数据库管理员角色,拥有管理数据库的最高权限
创建用户,并授权
create user 新用户 identified by 密码 default tablespace 表空间;//创建用户,并给他指定默认使用的表空间
conn 新用户/密码;//此时连接不了
grant connect,resource to 新用户;//给新用户connect和resource的权限,再conn就可以连接了;
二、给已存在的用户指定表空间
alter user username default tablespace userspace;
===============================================
创建表:=teacher表=======
create table teacher
(tno number(4) not null,
tname varchar2(14) not null,
tid char(18),
gender char(2),
birthdate date);
查看表:
desc teacher;
更改表:
alter table teacher add (sal number(7,2),hiredate date,wechat varchar2(30));
alter table teacher modify(tname varchar2(30));
alter table teacher drop column wechat;
更改列名:
alter table teacher rename column column to xingbie ;
edit,保存之后,/ 执行
增加主键:
alter table teacher add constraint pk_teacher
primary key(tno);
增加唯一约束:
alter table teacher add constraint uk_teacher_tname unique(tname);
增加检查约束:
alter table teacher add constraint ck_teacher_gender
check(gender in ('male','female'));
Add foreign key constraints:
alter table teacher add constraint fk_teacher_deptno_dept foreign key(deptno)
references dept(deptno);
1: First create a sequence object
CREATE SEQUENCE sq_num INCREMENT BY 1 START WITH 1 NOMAXVALUE NOCYCLE 2: When inserting a record, apply the sequence object on the primary key Suppose there is a customer table with a primary key bh, you can do this INSERT INTO customer VALUES( sq_num.NEXTVAL,'Zhang San',........)
CREATE SEQUENCE sq_name -- create a sequence
[start with n] [increment by n][ maxvalue n|nomaxvalue][cycle|nocycle][cache n|nocache];
sq_name.currval -- current sequence number
sq_name.nextval -- next sequence number
DROP SEQUENCE sq_name; -- delete Sequence ------------------------------------- 1. Create a sequence
CREATE SEQUENCE sq_teacher INCREMENT BY 1 START WITH 1 NOMAXVALUE NOCYCLE2. To view the current sequence value (view it in the dummy table dual), you must first initialize the sequence to view it as follows: first nextval (initialization) select sq_teacher.nextval from dual and then view select sq_currval from dual ----------- -------------------------------------------------- ---------- 1. First delete the sequence, then recreate it. But that's not the point of the present. This method is more convenient.
2. Modify the initial value by Increment By.
For example: if the sequence name is SeqTest2010_S, the initial value is 13, and now to set the initial value to 1020, the Increment By value is: 1007(1020-13)
2.1 Execute: Alter Sequence SeqTest2010_S Increment By 1007;
2.2 Execute: Select SeqTest2010_S.NextVal From Dual;
2.3 Execute: Alter Sequence SeqTest2010_S Increment By 1; The
modification is completed. Keep it simple --------------------------------------
number(3,1) 99.9
number (3,-1)990
number(2) 99
number 表示无限大
提供四种类型的约束保证完整性
域完整性
实体完整性
引用完整性
自定义完整性