sql複製資料表和表結構

2022-01-13 13:41:19 字數 1292 閱讀 1811

sql複製資料表 (select * into 與 insert into)

select * into目標表名from源表名

insert

into目標表名(fld1, fld2)select fld1, 5 from源表名

以上兩句都是將 源表 的資料插入到 目標表,但兩句又有區別的:

第一句(select into from)要求目標表不存在,因為在插入時會自動建立。 

第二句(insert into select from)要求目標表存在,由於目標表已經存在,所以我們除了插入源表的字段外,還可以插入常量,如例中的:5。

只複製表結構不複製表資料

select *  into 目標表名  from  源表名 where 1=0

**:資料庫 2009-05-28 15:03:34

閱讀151

字型大小:大

1:複製表結構及資料到新錶

select * into 目的資料庫名.dbo.目的表名 from 原表名

select * into my0735home.dbo.infomiantest from infomian

2:備份表的一部分列(不寫*而寫出列的列表)

select 列名1,列名2,列名3 into 目的資料庫名.dbo.目的表名 from 原表名

select id,title,mtype,stype,author,tel,nr into infomiantest2 from infomian

3:備份表的一部分行(加where條件)

select * into 目的資料庫名.dbo.目的表名 from 原表名 where id<10

select * into infomiantest2 from infomian where id<10

4:備份表的一部分列(不寫*而寫出列的列表)和一部分行(加where條件)

select 列名1,列名2,列名3 into 目的資料庫名.dbo.目的表名 from 原表名 where  id<10

5:只複製表的結構:如:select * inot t1 from titles where 1=2

select title_id,title,pub_name into t3

from titles t inner join publishers p

on t.pub_id=p.pub_id

**:

MySQL複製資料表

主題 下面是我在複製表結構以及資料時最常使用的搭配 table new 新錶 table old 原表 create table new like table old 完整複製原表的建表語句以建立新錶 insert into table new select from table old 完整複製原...

MySQL 複製資料表

假設現在有張資料表 users create table users userid int 10 unsigned not null username varchar 100 unique passwd varchar 100 default 123456 primary key userid en...

資料表結構

修改資料表 alter table 表名sql 的書寫不考慮順序,但是批量執行 需要要考慮好先執行哪些,後執行哪些 在修改資料表結構時,必須要明確 修改的字段中是否存在資料,例如 如果需要更改乙個欄位的約束為非空約束,那麼首先要保證該字段中已有的資料沒有null值。因此在做程式之前資料庫分析,設計是...