• 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;

  • 相关阅读:
    京东精益敏捷教练分享:敏捷助力产品创新!
    设计规范 | 详解组件控件结构体系
    Axure响应式进阶
    通讯录表设计
    TEST1
    c#练习四单元总结
    窗体控件应用总结(1)
    .NET(c#理解)
    test2-11
    test1-1
  • 原文地址:https://www.cnblogs.com/ZM-Rid/p/3608103.html
Copyright © 2020-2023  润新知