oracle 10g学习2

一、oracle中查看表、字段、约束和注释

1,(1)查看当前用户有哪些表

  select table_name from user_tables;

  (2)查看所有用户的表

  select table_name from all_tables;

  (3)查看所有表包括系统表

  select table_name from

2,查看s_emp中有哪些字段

  方法一:desc s_emp;

  方法二:select column_name from user_tab_columns where table_name='S_EMP';

  注意:在方法二中table_name后的' '中必须写严格区分大小写的表名。oracle中分为两种情况,单纯的sql语句不区分大小写,但是如果查询某个字符的话就需要区分大小写。如果写成's_emp',则不能查询出结果。当然还有一个方法是select column_name from user_tab_columns where table_name = upper('s_emp');

3,查看s_emp中一共有多少个字段

  select count(1)

  from user_col_comments

  where table_name = upper('s_emp');

4,查看当前用户下所创建的约束的名字

  select constraint_name

  from user_constraints;

5,查看s_emp表中所创建的约束名字

  select constraint_name

  from user_constraints

  where table_name='S_EMP';

6,查看s_emp表中约束的相关信息

  select constraint_name,constraint_type,search_condition

  from user_constraints

  where table_name='S_EMP';

7,查看s_emp表中的约束在哪列上起作用

  select constraint_name,column_name

  from user_cons_columns

  where table_name = 'S_EMP';

8,查看当前用户的所有对象

  select distinct object_type from user_objects;

9,查看当前用户的表包括回收站的表

  select object_name

  from user_objects

  where object_type='TABLE';

10,(1)获取s_emp表注释

    select comments

    from user_tab_comments

    where table_name ='S_EMP';

  (2)获取字段注释

    select comments

    from user_col_comments

    where table_name ='S_EMP';

注意:

    添加表注释:

    COMMENT ON table s_emp is '员工信息';

    添加字段注释:
    comment on column s_emp.id  is '员工号';
    comment on column s_emp.last_name is '姓';
    comment on column s_emp.first_name is '名';

原文地址:https://www.cnblogs.com/sq-software/p/5104446.html