根據乙個已存在的表,去建立乙個相同的表

2021-06-28 22:12:42 字數 714 閱讀 3378

//利用已存在的customer表來建立 customer2表

oracle :

create table customer2 as select * from customer

mssql:

select 

*  into 

customer3 

from 

customer (本人親測可以用)

mysql:

同oracle

create table customer2 as select * from customer(本人親測可以用)

//如果是要生成指定的列名呢請看 (這裡只介紹oracle的,語法上掌握以後,原理是一樣的)

若只有customer的id和name欄位並且在customer2中表結構是(cid,c_name);

那麼可以這麼寫

create table customer2 as select id cid,name c_name from customer

可以看出只是指定別名而已 ,mysql中是一樣的,mssql2000只是語法不一樣,但原理相同

(親測)

mysql:create table customer2 as select id as cid from customer;

mssql:select customer.id  into customer2 from customer;

用乙個表去更新另乙個表

朋友今天問我乙個問題 有兩張資料表 bureau area code 和 county code,我想用town code擷取前6位去和county code擷取前6位查詢,查到對應的county name該咋寫?下面先是兩張表結構 1 create table bureau area code 2...

根據乙個表的字段,更新另外乙個表的字段

update table a set latesttm u.tm,latestdata u.data from select from table b inner join select max tm newesttm from table b group by stcd v on drp.tm v...

存在乙個表而不在另乙個表的資料

方法一 僅適用單個字段 使用 not in 容易理解,效率低 select a.id from a where a.id not in select id from b 方法二 適用多個字段匹配 使用 left join.on.b.id isnull 表示左連線之後在b.id 欄位為 null的記錄...