oracle表的基本操作语句
来源:互联网 发布:win7下怎么卸载Ubuntu 编辑:程序博客网 时间:2024/06/05 16:11
这篇文章的内容包括:表的増删改查,字段的増删改查,主键、外键、唯一、非空、默认约束的増删改
查看自己用户的所有表:
select * from user_tab_comments;
www.2cto.com
创建表:
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 www.2cto.com
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); www.2cto.com
建表后添加非空约束
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;
2.更改列的属性
例:表table2中的列id为int型,现改为char型
alter table table2 alter column id char
3.增加列
A.例:在表table2中增加name列为char型
alter table table2 add name char(8)
B.例:在表table2中增加nob列为int型且设自增量为1,且不空
alter table table2 add nob int identity(1,1) not null
4.删除列
例:删除table2中的id列
alter table table2 drop column id
例:表table2中的列id为int型,现改为char型
alter table table2 alter column id char
3.增加列
A.例:在表table2中增加name列为char型
alter table table2 add name char(8)
B.例:在表table2中增加nob列为int型且设自增量为1,且不空
alter table table2 add nob int identity(1,1) not null
4.删除列
例:删除table2中的id列
alter table table2 drop column id
以上内容包括“表的増删改查”,“字段的増删改查”,“主键、外键、唯一、非空、默认约束的増删改”
练习时自然是安装以上内容的顺序不看文章自己手动敲出来
- oracle表的基本操作语句
- oracle基本操作语句
- oracle基本操作语句
- oracle基本操作语句
- ORACLE基本操作语句
- oracle基本操作语句
- oracle数据库的基本操作语句
- 基本的oracle查询操作语句
- ORACLE基本定义、操作语句
- oracle基本操作语句总结
- Oracle开发基本操作语句
- oracle 一些基本操作语句
- oracle 基本操作练习——简单的sql语句
- oracle基本操作语句(适合初学者)
- Oracle数据库操作基本语句随笔
- Oracle中SQL基本操作语句
- Oracle 第四记 基本操作语句
- oracle的基本操作
- 关于QQ弹窗的不好之处
- lotus表单中域的类型
- Android Log分析之法
- 纹理正确的映射到四边形上
- easyUI Pagination
- oracle表的基本操作语句
- poj1731 - Orders
- 【动态规划】受受的刷题计划
- 如何用SendMessage()函数传递字符串
- AudioToolbox学习笔记(转)
- java代理中对时间的格式化
- Flex 页面空白或Error #2032: 流错误处理惩罚办法
- linker截获API调用
- [centos6.2]修改dhcp服务日志的记录位置