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;

        

  • 相关阅读:
    yii 引入文件
    CodeForces 621C Wet Shark and Flowers
    面试题题解
    POJ 2251 Dungeon Master
    HDU 5935 Car(模拟)
    HDU 5938 Four Operations(暴力枚举)
    CodeForces 722C Destroying Array(并查集)
    HDU 5547 Sudoku(dfs)
    HDU 5583 Kingdom of Black and White(模拟)
    HDU 5512 Pagodas(等差数列)
  • 原文地址:https://www.cnblogs.com/canyangfeixue/p/2461724.html
Copyright © 2011-2022 走看看