天天看點

資料定義語言(DDL)

建立資料庫表:

create table uc

(

userid varchar2(53) not null,

userloginname varchar2(35) not null,

userpassword varchar2(25) not null,

userextend varchar2(1000)

);

在oracle中給表、列(字段)增加注釋以及讀取注釋

0、檢視表中有多少個列

 select tname,count(*) from col group by tname;

1、表添加注釋:

   sql>comment on table 表名 is '注釋';

   eg:comment on table uc is '使用者登入表';

2、列添加注釋:

   sql>comment on column 表名.列名 is '注釋';

   eg:comment on column uc.userloginname is '使用者登入名';

3、讀取表注釋:

  sql>select * from user_tab_comments where comments is not null;

  或select * from user_tab_comments; 

  eg:select * from user_tab_comments where comments is not null;

4:讀取列注釋:

 sql>select * from user_col_commnents where comments is not null and table_name='表名'

  或select * from user_col_comments where table_name='表名';

5:讀取表資訊

  desc 表名

6:向建立好的表中插入一個列:

  alter table 表名 add 列名 varchar2(25);

7:删除一個表的主鍵:

  alter table 表名 drop primary key cascade;

8:修改表名:

  alter table 舊表名 rename to 新表名;

  eg:alter table ucccc rename to uc;

9:檢視表名:

  sql> select tname from tab;

10:修改表的列(字段名):

  alter table 表名 rename column 舊字段名 to 新字段名稱;

11:修改表的列的資料類型(長度):

  alter table 表名 modify 列名 資料類型;

  eg:alter table uc modify userid varchar2(53);

   删除表中的列:

  alter table 表名 drop column 列名;

12:删除使用者:

  drop user ×× cascade

13:删除表:

1.delete (删除資料表裡記錄的語句)

  delete from表名 where 條件;

注意:删除記錄并不能釋放oracle裡被占用的資料塊表空間. 它隻把那些被删除的資料塊标成unused.

2.如果确實要删除一個大表裡的全部記錄, 可以用 truncate 指令, 它可以釋放占用的資料塊表空間

truncate table 表名;

   此操作不可回退.

   truncate和 delete隻删除資料不删除表的結構(定義)

3.drop語句将删除表的結構被依賴的限制(constrain),觸發器(trigger),索引(index); 依賴于該表的存儲過程/函數将保留,但是變為invalid狀态.

 drop table 表名;

4.删除表空間:

 drop tablespace tablespace_name including contents and datafiles;