方式一、如果寫代碼
select * into [目標資料庫B].DBO.表名 from. [源資料庫A].DBO.表名
方式二、如果不寫代碼,可以用導入的方式
復製表結構(如果目標資料庫已經存在,此步跳過)
1、打開並連接Sql Server,在源資料庫DATA_A(源資料庫名稱)上右鍵,然後依次點擊「編寫表腳本為」→「CREATE到」→「新查詢編輯器窗口」。
2、在第1步產生的編輯器中按」crtl+a「組合鍵全選內容,然後右鍵「復制「(或按"crtl+c"鍵)。
3、新建查詢,然後右鍵「粘貼」(或ctrl+v);如圖所示,將代碼中DATA_A(源資料庫名)改為DATA_B(目標資料庫名)。接著右鍵單擊」執行「執行代碼。
4、在目標資料庫的表結構中就可以看到被復制過來的表了。
表的數據內容復制
選中目標資料庫DATA_B然後點擊」任務「→」導入數據「。
進入」SQL Server導入導出向導「,根據提示步驟操作。
選擇數據源(源資料庫)。
選擇目標(目標資料庫)、指定表復制或查詢。
選擇源表和源視圖:設置源表和目標表後,單擊「編輯映射」按鈕,在彈出窗口中選中「啟用標識插入」。(否則後面會出錯)
一直點擊「下一步」至最後完成操作。
Ⅱ 如何用sql語句復制一張表
1、原表存在的話這樣用:insert into a select * from b
2、原表不存在的話這樣用:select * into a from b
Ⅲ SQL如何復製表結構
1、既復製表結構也復製表內容的SQL語句:
CREATE TABLE tab_new AS SELECT * FROM tab_old;
2、只復製表結構不復製表內容的SQL語句:
CREATE TABLE tab_new AS SELECT * FROM tab_old WHERE 1=2;
3、不復製表結構,只復制內容的sql語句:
SELECT vale1, value2 into Table2 from Table1
(3)復製表sql流程圖擴展閱讀:
SQL中常用的語句:
1、說明:創建資料庫
CREATE DATABASE database-name
2、說明:刪除資料庫
drop database dbname
3、說明:創建新表
create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..)
根據已有的表創建新表:
A:create table tab_new like tab_old (使用舊表創建新表)
B:create table tab_new as select col1,col2… from tab_old definition only
4、說明:刪除新表
drop table tabname
5、說明:增加一個列
Alter table tabname add column col type
6、說明:添加主鍵
Alter table tabname add primary key(col)
7、說明:刪除主鍵
Alter table tabname drop primary key(col)
8、說明:創建索引
create [unique] index idxname on tabname(col….)
9、刪除索引
drop index idxname
Ⅳ 如何復製表SQL
1、既復製表結構也復製表內容的SQL語句:
CREATE
TABLE
tab_new
AS
SELECT
*
FROM
tab_old;
2、只復製表結構不復製表內容的SQL語句:
CREATE
TABLE
tab_new
AS
SELECT
*
FROM
tab_old
WHERE
1=2;
3、不復製表結構,只復制內容的sql語句:
SELECT
vale1,
value2
into
Table2
from
Table1
(4)復製表sql流程圖擴展閱讀:
SQL中常用的語句:
1、說明:創建資料庫
CREATE
DATABASE
database-name
2、說明:刪除資料庫
drop
database
dbname
3、說明:創建新表
create
table
tabname(col1
type1
[not
null]
[primary
key],col2
type2
[not
null],..)
根據已有的表創建新表:
A:create
table
tab_new
like
tab_old
(使用舊表創建新表)
B:create
table
tab_new
as
select
col1,col2…
from
tab_old
definition
only
4、說明:刪除新表
drop
table
tabname
5、說明:增加一個列
Alter
table
tabname
add
column
col
type
6、說明:添加主鍵
Alter
table
tabname
add
primary
key(col)
7、說明:刪除主鍵
Alter
table
tabname
drop
primary
key(col)
8、說明:創建索引
create
[unique]
index
idxname
on
tabname(col….)
9、刪除索引
drop
index
idxname
Ⅳ SQL server 資料庫 如何把一張表復制到另一個資料庫表中
SQLserver資料庫如何把一張表復制到另一個資料庫表中的方法。
如下參考:
1.首先,在桌面上單擊「ManagementStudio」圖標。
Ⅵ sqlserver在同一個資料庫里如何復製表結構
sqlserver在同一個資料庫里復製表結構的具體操作步驟如下:
1、首先,選中目標資料庫然後點擊任務導入數據:
Ⅶ SQL語句 怎麼把一個表的數據復制到另外一個表裡面
SQL語句把一個表的數據復制到另外一個表裡面的步驟:
1、打開SQL,登錄到一個資料庫中,依次點擊「工具」——「導出表」,在彈出的界面中選擇一個用戶,列出這個用戶下面的所有表。
Ⅷ 如何復製表SQL
1、既復製表結構也復製表內容的SQL語句:
CREATE TABLE tab_new AS SELECT * FROM tab_old;
2、只復製表結構不復製表內容的SQL語句:
CREATE TABLE tab_new AS SELECT * FROM tab_old WHERE 1=2;
3、不復製表結構,只復制內容的sql語句:
SELECT vale1, value2 into Table2 from Table1
(8)復製表sql流程圖擴展閱讀:
SQL中常用的語句:
1、說明:創建資料庫
CREATE DATABASE database-name
2、說明:刪除資料庫
drop database dbname
3、說明:創建新表
create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..)
根據已有的表創建新表:
A:create table tab_new like tab_old (使用舊表創建新表)
B:create table tab_new as select col1,col2… from tab_old definition only
4、說明:刪除新表
drop table tabname
5、說明:增加一個列
Alter table tabname add column col type
6、說明:添加主鍵
Alter table tabname add primary key(col)
7、說明:刪除主鍵
Alter table tabname drop primary key(col)
8、說明:創建索引
create [unique] index idxname on tabname(col….)
9、刪除索引
drop index idxname