oracle(2)
oracle 建表语句和约束
在scott身份会有四个默认表
分别在

创建表
--创建表 create table java1019( 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 java1019(jid)--外检约束 )
添加数据
--新增数据 insert into java1019 values(1,'晓红','女','山东上海',to_date('1999-09-09','yyyy-mm-dd'));
因为库的原因 在添加时间的时候必须要用to_date函数才行
修改表结构:

删除表:

trancate table 比 delect from 更加高级 而且删除后不能回滚 不能用加where

快速复制一张表出来
--复制表结构 create table java1020 as select * from java1019 where 1=2
插入来自其他表里的数据
--插入来自其他表中的数据 insert into java1020 select * from java1019 where jid=1;
去掉where 就是全部插入 带where就是条件插入
--复制表的部分数据并且排序 create table java1021 as select jid,jname from java1019 order by jid
order by 是排序函数

授予权限必须要在系统管理员身份下登录才可以
--用系统管理员身份创建用户 create user xiaolan 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;

浙公网安备 33010602011771号