查看表主键
select a.constraint_name, a.table_name, b.constraint_name
from user_constraints a, user_constraints b
where a.constraint_type = 'R' --R表示外键
and b.constraint_type = 'P' --P表示主键 两个选一个
and a.r_constraint_name = b.constraint_name
配置PL/SQL
Tools-Preference首选项 地址栏中分别写
D:\company\Installation Package\Linux\instantclient_11_2(plsql link)
D:\company\Installation Package\Linux\instantclient_11_2(plsql link)\oci.dll
公司数据库
CBSFLCP72
CBSFLCP72
192.168.66.248/FCUBS
CBSFLCP
CBSFLCP
Database:192.168.66.70/FCUBS
显示oracle系统时间
select to_char(sysdate,'YYYY-MM-DD HH24:MI:SS') from dual;
复制表
如果两个表结构一样
insert into table_name_new select * from table_name_old
如果两个表结构不一样:
insert into y(字段1,字段2) select 字段1,字段2 from x
只复制表结构
create table 用户名.表名 as select * from 用户名.表名 where 1=2
删除users这个表 drop table users;
查看表desc 表名;
查看表插入的数据 select * from users;
查询某项为空或不是为空的人 select * from users where birthday is null/is not null;
建表的几个约束
not null
unique 唯一 不能重复但是可以为空 可以为多个
primary key 只能唯一 最多一个主键
foreign key 外键
check 条件约束
主键被外表引用的不可以直接删除 例emp的主键 被dept表引用 想删除
向表中添加注释
comment on table test is 'hehe';
comment on column test.a is 'hehe';
select * from user_col_comments ;查看有注释的
创建三个表
create table goods (goodsId char(8) primary key,
goodsName varchar2(20),
unitprice number(10,2) check(unitprice>0),
category varchar2(20),
provider varchar2(20))
create table customer(customerId char(8) primary key,
name varchar2(50) not null,
address varchar2(50),
email varchar2(20) unique,
sex char(2) default '男' check (sex in ('男','女')),
cardId char(18)
)
create table purchase (customerId char(8) references customer(customerId),
goodsId char(8) references goods(goodsId),
nums number(10) check (nums between 1 and 30))
删除表中主键被个、另一张表作为外键被引用的表
删除主键 alter table aa1 drop primary key cascade;
有外键的表
create table aa1(
xh number primary key,
xm varchar2(10))
create table aa2(
zj number primary key,
xh number,
foreign key(xh) references aa1(xh)
aa2这张表有外键xh在aa1表中做主键 所以不能直接删除aa1得先删除aa2 或者drop table aa1 cascade
向表中添加主键约束 alter table student add constraint pk_student primary key(studentid);
4、向表中添加外键约束 ALTER TABL