zoukankan      html  css  js  c++  java
  • oracle11g创建修改删除表

    oracle11g创建修改删除表

    我的数据库名字: ORCL         密码:123456

    1、模式

    2、创建表

    3、表约束

    4、修改表

    5、删除表

    1、模式

    set oracle_sid=ORCL

    sqlplus /nolog

    1)进入同名模式(首次使用可能需要设置见附录,我设置scott用户的密码 123)

    connect scott/123

    show user

    2)进入sys模式(无法删除sys列)

    connect  /as sysdba

    show user

    3)进入public模式

    connect sys/123456 as sysoper

    show user

     

    ORA-12560: TNS: 协议适配器错误

         一般情况下,造成ORA-12560: TNS: 协议适配器错误的问题的原因有三个:

        1.监听服务没有起起来。windows平台个一如下操作:开始---程序---管理工具---服务,打开服务面板,启动oraclehome92TNSlistener服务。

        2.database instance没有起起来。windows平台如下操作:开始---程序---管理工具---服务,打开服务面板,启动oracleserviceXXXX,XXXX就是你的database SID.比如我的SID就是ORCL

        3.右键我的电脑,属性--高级--环境变量---系统变量--新建,变量名=oracle_sid,变量值=XXXX,XXXX就是你的database SID

        造成上述的主要原因是,我新安装的数据库实例oratest将我原有的ORCLsid给覆盖了,这里通过设置环境变量的方法来进行控制sid

    2、创建表

    先进入同名模式(普通用户没权限建表)

    connect scott/123

    1建表,表名:productinfo

    Create table productinfo(

    ProductId varchar2(10) constraint P_Id primary key,

    ProductName varchar2(10) not null,

    ProductPrice number(8,2) constraint P_Price check(ProductPrice between 0 and 1000),

    Quantity number(10)

    );

    2)创建临时表

    Create global temporary table temporary_table(

    ID number(2) primary key,

    Name varchar2(20)

    )

    On commit Delete rows; 

    3)利用子查询创建表

    Create table P_select(P_Id,P_Name)

    As

    Select ProductId,ProductName From Productinfo where ProductPrice > 10;

    3、表约束

    1)添加唯一约束

    Alter table productinfo add constraint P_Name Unique(ProductName);

    2)删除唯一约束

    Alter table productinfo drop Unique(ProductName);

    3)约束状态

    禁用约束

    Alter table productinfo disable constraint P_Price;

    激活约束

    Alter table productinfo enable constraint P_Price;

    4)查询约束信息

    Select constraint_name,constraint_type,deferred,status

    From user_constraints 

    where table_name='PRODUCTINFO';

    ‘PRODUCTINFO’一定要大写

    4、修改表

    1)添加新列

    Alter table productinfo

    ADD(Category number(6) );

    2)修改列的类型

    Alter table productinfo

    Modify Category varchar2(10);

    3)修改列名

    Alter table productinfo rename column Category to Desperation; 

    4)删除列

    Alter table productinfo

    Drop (Desperation);

    5表参数修改

    Alter table productinfo

    Pctfree 10 pctused 70 ;

    6)表结构重组

    Alter table productinfo move;

    7)表重命名

    productinfo 改为 product

    Rename productinfo to product;

    product 改为 productinfo

    Alter table product rename to productinfo;

    8)为表和列添加注释

    Comment on table productinfo IS '商品信息';

    Comment on column productinfo.ProductName IS '商品名称';

    (给列加注释:SQL>comment on column 表名.列名 is '列注释';)

    5、删除表

    Drop table productinfo;

    断开连接:exit

    附录:

    第一次使用scott

     

    MYDB 设置为新密码设置为 123

     

    新进入SYS模式,在此模式中修改 Scott

     

    连接scott更改密码

    输入新口令时窗口不显示输入字符

  • 相关阅读:
    taro 列表渲染
    taro 事件处理
    taro 项目、代码说明
    taro 开发注意点
    taro 知识点
    taro 学习资料
    egg 官方文档之:框架扩展(Application、Context、Request、Response、Helper的访问方式及扩展)
    node 学习资料
    node api 之:fs
    node api 之:stream
  • 原文地址:https://www.cnblogs.com/landiljy/p/4464207.html
Copyright © 2011-2022 走看看