标签:not 外键 efault 用户 右外连接 name ESS arch use
--创建表
create table java1018(
jid int primary key,--主键约束
jname varchar2(10) not null,--非空约束
jsex char(5) check(jsex in (‘男‘,‘女‘)),--检查约束
jaddress varchar2(30) default ‘山东淄博‘,--缺省约束
jbirth date
)
create table grade(
gid number primary key,
jid int,
math number,
foreign key(jid) references java1018(jid)--外键约束
)
--新增数据
insert into java1018 values(1,‘小红‘,‘男‘,‘山东济南‘,to_date(‘1999-09-09‘,‘yyyy-mm-dd‘));
insert into java1018(jid,jname,jsex) values(2,‘小绿‘,‘男‘);
select * from java1018
--复制表结构
create table emp02 as select * from emp where 1=2;
select * from emp02
--插入来自其他表中的数据
insert into emp02 select * from emp where deptno=20
--复制表的部分数据
create table emo03 as select empno,ename,job,sal,comm from emp order by sal
select * from emo03
--用系统管理员身份创建用户
create user xiaohong identified by 123456;
--赋予用户连接数据权限
grant connect, resource to xiaohong;
--赋予权限
GRANT SELECT ON scott.java1018
TO xiaohong WITH GRANT OPTION;
--取消权限
REVOKE SELECT ON scott.java1018 FROM xiaohong;
select * from scott.java1018
--内连接
select * from emp
select * from dept
select * from emp join dept on emp.deptno=dept.deptno
select * from emp,dept where emp.deptno=dept.deptno
--给表起别名
select * from emp e join dept d on e.deptno=d.deptno
--左外连接
select * from dept left join emp on emp.deptno=dept.deptno
--右外连接
select *from emp right join dept on emp.deptno=dept.deptno
--全外连接
select * from emp full join dept on emp.deptno=dept.deptno
标签:not 外键 efault 用户 右外连接 name ESS arch use
原文地址:https://www.cnblogs.com/kun123/p/12558100.html