这篇文章的内容包括:表的増删改查,字段的増删改查,主键、外键、唯一、非空、默认约束的増删改
查看自己用户的所有表:
select * from user_tab_comments;
创建表:
create table cqytest(
id number(1),
username varchar2(11),
password varchar2(11)--最后一个字段后面必须没有逗号
)tablespace cqyspace;
复制表:
create table test1 as select * from cqy.cqytest; --复制cqy用户的cqytest表
删除表:
drop table test1 cascade constraints;
给表添加注释:
comment on table cqytest is '我的测试表';
给字段添加注释:
comment on column cqyt1.id is '主键';
修改字段名:
alter table cqytest rename column id to userid;
添加字段:
alter table cqytest add email varchar2(11);
删除字段:
alter table cqytest drop column email;
修改字段类型:
alter table cqytest modify email varchar2(20);
查询所有约束:
select constraint_name from user_cons_columns;
建表时添加默认值、主键、外键,非空约束
create table cqyt1(
id number(11) not null primary key,--非空,主键,唯一(unique),foreign key id references cqytable
groupid number(11) check(groupid>22 and groupid<33),--条件约束
username varchar2(20),
password varchar2(20)
)tablespace cqyspace;
create table cqyt2(
id number(11),foreign key (id) references cqyt1(id),--建表时添加外键
username varchar2(20),
password varchar2(20)
)tablespace cqyspace;
建表后添加主键
alter table cqyt2 modify (id primary key); --不带约束名
alter table cqyt add constraint cqyt_pk_id primary key(id);--cqyt_pk为约束名
建表后添加外键
alter table cqyt4 add constraint cqyt4_fk_cqyt1_id foreign key (id) references cqyt1(id);
建表后添加非空约束
alter table cqyt2 modify (username not null);
建表后添加唯一性约束
alter table cqyt2 modify (username unique);
建表后添加默认值
alter table cqyt2 modify username default 'uu';
建表后添加条件约束
alter table cqyt2 add constraints cqyt2_ck_id check (id>11 and id<20);
删除约束
alter table cqyt4 drop constraint cqyt4_pk;
以上内容包括“表的増删改查”,“字段的増删改查”,“主键、外键、唯一、非空、默认约束的増删改”
练习时自然是安装以上内容的顺序不看文章自己手动敲出来
分享到:
相关推荐
Oracle Sql语句转换成Mysql Sql语句java 源码,非常简单,只要给定源oracle sql语句地址,和生成目标文件地址运行即可。
查看oracle表空间和临时表空间的使用情况、当前用户下的表所占空间大小表空间物理文件的名称和大小,是oracle DBA的利器哦
查询ORACLE 系统中当前会话正在执行的有关SQL语句。
SQL_Server,Oracle,DB2数据库SQL语句比较
oracle Sql语句二 oracle Sql语句二
ORACLE数据库优化之SQL语句的并行处理.pdf
oracle性能优化中SQL语句优化,简单的优化思想、常见的优化命令
oracle监听执行,可以监听应用执行的sql语句
Mysql的表对象Sql语句转换单表,转换成Oracle创建表sql,在样本.txt粘贴Mysql的单表所有字段信息,输入表名。就会在控件台输出转换后的Oracle语句。
从别处看到的Oracle常用性能监控SQL语句,不错。共享。
Oracle学习,常用sql语句汇总,适合新手使用。
sqlserver自动生成sql语句工具sqlserver转oracle
oracle查找定位占用临时表空间较大的SQL语句方法,包括:(1)造成临时表空间暴涨的SQL还在运行中(2)造成临时表空间暴涨的SQL已经运行过了。
Oracle添加字段的完整语句,oracle 添加字段时判断字段是否已经存在,sqlserver判断字段是否存在并添加
Oracle sql语句大全. sql语句的优化资料
Oracle SQL Profiler,自己设计算法写的一款非常好用的抓取Oracle数据库SQL语句的工具,可以再没有源码的情况下监控ORACLE数据库服务器的v$sqlarea视图抓取出从点击开始按钮到点击结束按钮期间执行过的SQL语句。...
对ORACLE-SQL进行一些布局优化,更新它的格式
oracle常用SQL语句下载 oracle常用SQL语句下载 oracle常用SQL语句下载
oracle消耗资源的sql查询语句记录