zoukankan      html  css  js  c++  java
  • 修改表

    1添加列,下面这个例子使用alter table 语句向table1添加一个名为column1的列

    alter table table1

    add column1 interger;

    2修改列

       1修改列的长度

       alter table table1 modify  status varchar2(15);

       2修改数字列的精度

       alter table  modify id number(5);

       3修改列的数据类型

       alter table table1 modify status char(15);

       4修改列的默认值

       atler table table1 modify column1 default sysdate-1;

       5删除列

       alter table table1 drop column column

    3添加约束

       1 check, not null,primary key,foreign key,unique,check,option,read only

    4删除约束

    aler table table1 drop constraint constraint1;

    5禁用约束

    alter table table1 add constraint   constraint1 unique disable;

    6启用约束

    alter table table1 enable table1 enable constraint constraint1;

    7获得有关约束的信息

    select constraint_name,constraint_type,status,deferrable(延迟),deferred from user_constraints where table_name='table1';

    8获得有关列的约束的信息

    下面这个例子检索user_cons_columns中order_status2表constraint_name和column_name;

    column colum_name format a15

    select constraint_name,column_name from user_cons_columns where table_name='order_status2';9

    9重命名表

    rename table1 to table2;

    10向表添加注释

    注释有助于记住表或列的用途。使用comment语句可以为表或列添加注释。下面这个例子为order_status2表添加注释:

    comment on table order_status2 is

    'order_status2 stores the state of an order';

    下面这个例子为order_status2.last_modified 列添加注释:

    comment on colum oder_status2.last_modified is

    'last_modified stores the date and time the order was modified last';

    11获得表的注释

    select * from user_tab_comments

    where table_name='order_status';

    12获得列的注释

    使用user_col_comments可以获得有关列的注释。

    select *

    from user_col_comments

    where table_name='order_status';

    13创建序列

      create sequence sequence_name;

       获取有关序列的信息

      select * from sequence_name

       下面这个例子是从用户中获取有关序列的信息

     select * from user_sequences;

    14 创建索引

       create [unique] index index_name on table_name(column_name,[column_name...])

       tablespace tab_space;

      例如:创建单列索引;create index customers_last_name_idx on customers(last_name);

            创建唯一索引可以实现列值的唯一性。例如下面的语句对customers.phone列创建一个唯一索引customers_last_name_idx;

            create unique index customers_phone_idx on customers(phone);

     我们也可以多列创建复合索引,例如,下面这个语句就对employee表的firs_name和last_name列创建一个复合索引employee_first_last_name_idx on

    employees(first_name,last_name);

    15创建基于函数的索引

     上节已经介绍了索引customers_last_name_idx

      它是这样创建的 create index customers_last_name_idx on customers(last_name);

     假设执行下面这个查询:select first_name,last_name  from customers

     where last_name=upper('price');

    由于使用了upper函数,因此创建的所有就不会被执行

    要执行就得创建基于函数的索引:

    create index customers_last_name_func_idx on customers(upper(last_name));

    例外为了利用基于函数的索引,DBA必须初始化参数query_rewrite_endabled

    alter system set query_rewrite_enabled=true;

    16获取有关索引的信息

      索引列的信息包括index_name,table_owner,table_name,uniqueness,status;select index_name,table_name,uniqueness,status
      2  from user_indexes
      3  where table_name in('customers','employees');
     

    17获取有关列索引的值

     select index_name,table_name,column_name from

     user_ind_columns

    where table_name in('customers','employees');

    18 修改索引

    alter index index_name rename to index_name2;

    19删除索引

    drop index index_name;

        

  • 相关阅读:
    HyperV Server 2008 R2 包含简体中文 下载
    Javascript实现把网页中table的内容导入到excel中的几种方法
    C# WebRequest WebClient Post请求 无乱码
    聊聊我对开发项目选技术的看法
    聊聊我对开发项目选技术的看法2
    企业的虚拟化发展
    不成文的期望
    Deep Zoom Composer 小工具 三步 5分钟
    2009829 周末
    复制文章时自动在文章末尾加上来源网址的代码
  • 原文地址:https://www.cnblogs.com/canyangfeixue/p/2461724.html
Copyright © 2011-2022 走看看