最近一直在建各種表和視圖,記錄一下代碼。
創(chuàng)建新表
1.數(shù)據(jù)全部來自另一個表時(可起到復(fù)制表當(dāng)備份作用。):
? ? create table tablename as select * from table2
2.創(chuàng)建一個空表時:
? ? create table tablename (
? ? column1 varchar(225) primary key,
? ? column2 number(10) not null,
? ? column3 varchar(2) )
創(chuàng)建視圖
有時連接的表太多,數(shù)據(jù)量太大時已經(jīng)不好建表,但是每次重新輸入語句查詢又很不方便,這時候推薦創(chuàng)建視圖。視圖作為一個查詢結(jié)果的虛擬表,能夠讓數(shù)據(jù)更簡單?;蛘哂械谌饺藛T查看的時候,視圖的只讀權(quán)限也很適合。
? ? create or replace view viewname as select from(
? ? select a.*,b.* from table a left join table b
? ? on a.columnA=b.columnA)