zoukankan      html  css  js  c++  java
  • Oracle课堂实验一“表的使用”代码。


    --创建本地管理表空间CustomerTBS
    CREATE TABLESPACE CustomerTBS
             DATAFILE 'd:Oracle11product11.2.0oradataCustomerTBS.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;

  • 相关阅读:
    insert into output使用
    内插字符串$与复合格式设置{}
    网站连接数据库连接不上原因是ip地址与端口号格式不对
    IIS中的MIME类型设置
    select distinct
    复制表备份表的问题
    一些碎知识
    题解【洛谷P3574】[POI2014]FAR-FarmCraft
    题解【洛谷P6029】[JSOI2010]旅行
    题解【BZOJ4472】[JSOI2015]salesman
  • 原文地址:https://www.cnblogs.com/ZM-Rid/p/3608103.html
Copyright © 2011-2022 走看看