SQL Server數(shù)據(jù)庫中不同數(shù)據(jù)庫相同表結(jié)構(gòu)的數(shù)據(jù)導入
作者:奮斗成就人生
本文我們主要介紹了在SQL Server數(shù)據(jù)庫的不同數(shù)據(jù)庫之間實現(xiàn)相同表結(jié)構(gòu)的數(shù)據(jù)導入的方法,并給出了全部的實現(xiàn)代碼,希望能夠?qū)δ兴鶐椭?/div>
SQL Server數(shù)據(jù)庫中,數(shù)據(jù)庫不同,但表結(jié)構(gòu)相同數(shù)據(jù)可以相互導入嗎?答案是肯定的。本文我們就來介紹這一過程,接下來就讓我們來一起了解一下吧。
在SQL Server數(shù)據(jù)庫下,新建兩個不同的數(shù)據(jù)庫名字,然后在數(shù)據(jù)庫下創(chuàng)建兩個相同結(jié)構(gòu)的表(建議使用SQL語句),比如:
在soutest數(shù)據(jù)庫下寫入以下語句:
- create table Employee1
- (
- EmployeeID int primary key ,
- EmployeeName varchar(20) not null,
- EmployeeAge smallint not null,
- EmployeeSex char(2) default '女',
- EmployeeCellPhone int not null,
- EmployeeAddress nvarchar(50),
- EmployeeComments nvarchar(1000)
- )
然后往這個表中插入數(shù)據(jù)(注:如果在源表中設置了標識符的,請在下面語句前加入set identity_insert on, ***加入set identity_insert off):
- insert into Employee(EmployeeID,EmployeeName,EmployeeAge,EmployeeCellPhone,EmployeeAddress,EmployeeComments)
- values(2,'xd',12,123455,'beijing', 'handsome man')
- insert into Employee(EmployeeID,EmployeeName,EmployeeAge,EmployeeCellPhone,EmployeeAddress,EmployeeComments)
- values(3,'xwxe',12,123455,'shanghai', ' a good boy')
我們將在test下創(chuàng)建表的語句放在另一個數(shù)據(jù)庫destest下執(zhí)行,這時,我們建立了一個表。再在這個數(shù)據(jù)庫下執(zhí)行以下語句:
- insert destest.dbo.Employee (EmployeeID,EmployeeName,EmployeeAge,EmployeeSex,EmployeeCellPhone,EmployeeAddress,EmployeeComments)
- select EmployeeID,EmployeeName,EmployeeAge,EmployeeSex,EmployeeCellPhone,EmployeeAddress,EmployeeComments
- from soutest.dbo.Employee
至此,工作全部結(jié)束。
關于SQL Server數(shù)據(jù)庫中兩個不同數(shù)據(jù)庫但相同表結(jié)構(gòu)的數(shù)據(jù)導入的知識就介紹這么多了,希望本次的介紹能夠?qū)δ兴鶐椭?/p>
【編輯推薦】
責任編輯:趙鵬
來源:
博客園

相關推薦


















