Oracle课堂实验一“表的使用”代码。
2014-11-18 17:13
411 查看
--创建本地管理表空间CustomerTBS
CREATE TABLESPACE CustomerTBS
DATAFILE 'd:\Oracle11\product\11.2.0\oradata\CustomerTBS.dbf' SIZE 130M
EXTENT MANAGEMENT LOCAL AUTOALLOCATE;
--创建用户ORACLEUSER,指定默认表空间为CustomerTBS,在该表空间的配额10MB
create user ORACLEUSER identified by 514224717
default tablespace CustomerTBS
quota 10M on CustomerTBS;
--授予用户创建表的权限
grant create table to ORACLEUSER;
--为了登录,为用户创建用户登录权限
grant connect,resource to ORACLEUSER;
--CustomerType表的创建
create table CustomerType(
TypeId number(10) primary key,
TypeName varchar2(20)
)
--Customer表的创建
CREATE TABLE Customer(
Id number(10) primary key,
name varchar2(20) not null,
pwd varchar2(20) default 111111,
type number(10) constraint FK_Customer references CustomerType(TypeId)
);
--往CustomerType表中插入数据
insert into CustomerType values(1,'普通客户');
insert into CustomerType values(2,'中级客户');
insert into CustomerType values(3,'高级客户');
--往Customer表中插入数据
insert into Customer values(1,'张三','514224717',1);
insert into Customer values(2,'李四','514224717',2);
insert into Customer values(3,'王五','514224717',3);
--修改数据
update CustomerType set TypeName='初级客户' where TypeId='1';
update Customer set name='张二' where id='1';
--删除数据
delete from customer where name='张二';
delete from customertype where typename='初级客户';
--用子查询创建表VIPCustomer(Id,name,pwd,type),将Customer表中type为000000的数据复制到此表中
create table VIPCustomer(Id,name,pwd,type) as select Id,name,pwd,type from customer;
insert into VIPCustomer(Id,name, pwd,type) (select Id, name, pwd, type from Customer where type='000000');
--修改表结构,为Customer表增加birthday列,修改列、删除列。
alter table Customer
add(birthday date);
alter table Customer rename Column type to typename;
alter table Customer drop column type;
CREATE TABLESPACE CustomerTBS
DATAFILE 'd:\Oracle11\product\11.2.0\oradata\CustomerTBS.dbf' SIZE 130M
EXTENT MANAGEMENT LOCAL AUTOALLOCATE;
--创建用户ORACLEUSER,指定默认表空间为CustomerTBS,在该表空间的配额10MB
create user ORACLEUSER identified by 514224717
default tablespace CustomerTBS
quota 10M on CustomerTBS;
--授予用户创建表的权限
grant create table to ORACLEUSER;
--为了登录,为用户创建用户登录权限
grant connect,resource to ORACLEUSER;
--CustomerType表的创建
create table CustomerType(
TypeId number(10) primary key,
TypeName varchar2(20)
)
--Customer表的创建
CREATE TABLE Customer(
Id number(10) primary key,
name varchar2(20) not null,
pwd varchar2(20) default 111111,
type number(10) constraint FK_Customer references CustomerType(TypeId)
);
--往CustomerType表中插入数据
insert into CustomerType values(1,'普通客户');
insert into CustomerType values(2,'中级客户');
insert into CustomerType values(3,'高级客户');
--往Customer表中插入数据
insert into Customer values(1,'张三','514224717',1);
insert into Customer values(2,'李四','514224717',2);
insert into Customer values(3,'王五','514224717',3);
--修改数据
update CustomerType set TypeName='初级客户' where TypeId='1';
update Customer set name='张二' where id='1';
--删除数据
delete from customer where name='张二';
delete from customertype where typename='初级客户';
--用子查询创建表VIPCustomer(Id,name,pwd,type),将Customer表中type为000000的数据复制到此表中
create table VIPCustomer(Id,name,pwd,type) as select Id,name,pwd,type from customer;
insert into VIPCustomer(Id,name, pwd,type) (select Id, name, pwd, type from Customer where type='000000');
--修改表结构,为Customer表增加birthday列,修改列、删除列。
alter table Customer
add(birthday date);
alter table Customer rename Column type to typename;
alter table Customer drop column type;
相关文章推荐
- [导入]安装Oracle后,经常使用的修改表空间的SQL代码
- Oracle恢复实验一:使用添加数据文件之前的控制文件
- Linq to Oracle 使用教程(八)使用 T4 模版生成代码
- oracle欲出纯托管代码的ODP.NET,现接受小范围预览版本使用申请
- Oracle 10g中使用RMAN进行备份恢复的几个实验手记
- 使用Oracle Wrap工具加密你的代码
- Oracle代码封装工具和DBMS_DDL包的使用
- Oracle中对象表的定义,nested table的使用.--附带Route下载的老版本代码
- 使用Oracle Unwrapper 破解 Oracle Wrapper 后的代码
- BizTalk动手实验(十二)WCF-Oracle适配器使用
- [导入]安装Oracle后,经常使用的修改表空间的SQL代码
- 使用Oracle Wrap工具加密你的代码
- 安装Oracle后,经常使用的修改表空间的SQL代码
- Oracle存储过程中执行查询返回的结果集,并使用java代码调用【转】
- 使用Oracle Wrap加密代码
- 使用Oracle Wrap工具加密你的代码
- 使用Oracle Wrap工具加密你的代码
- 在 Oracle中使用UTL_SMTP 进行邮件发送的例子代码
- jdbc使用DataSource连接mysql,postgresql,oracle的代码
- oracle实验31:使用PL/SQL,书写一个最简单的块