Oracle 基本 Sql
1,新建用户 create user [用户名] identified by [密码];
2,删除用户 drop user [用户名] ;
3,创建Session权限,否则不可以连接登陆 grant create session to [用户名];
4,解除锁定 alter user [用户名] account unlock;
5,修改用户密码 alter user [用户名] identified by [新密码];
6,锁定用户 alter user [用户名] account lock;
7,以dba 登陆 conn sys/password as sysdba;
8,角色 connect--创建会话 resource--建表增删改查 DBA--数据库管理员 grant connect,resource to [用户名];
9,查询的时候,如果没有 from 表,必须写上 dual
10,添加一个序列 create sequence test_tid minvalue 1 start with 1 increment by 1;
11,清空表 truncate table [表名称]
12,案例
--创建 test 表
create table test (
tid number not null primary key,
tname varchar2(20)
);
--查询 test 表
select * from test;
--删除 test 表
drop table test;
--添加一个序列
create sequence test_tid minvalue 1 start with 1 increment by 1;
--测试序列
select test_tid.nextval from dual;
--添加test记录并使用序列
insert into test(tid,tname) values(test_tid.nextval,'t1');
14,得到系统时间select sysdate from dual
15,系统guid SYS_GUID();
删除索引:
drop index PK_fsoReplan
删除主键:
ALTER TABLE fsoreplan drop CONSTRAINT PK_fsoReplan
删除外键:
ALTER TABLE tablea_tableb drop CONSTRAINT FK_AB
创建主键:(多个主健一起创建)
ALTER TABLE fsoreplan add CONSTRAINT PK_fsoReplan PRIMARY KEY (RepolicyNo,ReendorNo, RepayNo, SerialNo, ReinsMode,BelongType,PayType);
注:fsoreplan 是表名,PK_fsoReplan 是主键名,FK_AB是外键名;