在SQL-Server数据库下,新建两个不同的数据库名字,然后在数据库下创建两个相同结构的表(建议使用SQL语句),比如:在soutest数据库下写入以下语句:
1 create table Employee1
2 (
3 EmployeeID int primary key ,
4 EmployeeName varchar(20) not null,
5 EmployeeAge smallint not null,
6 EmployeeSex char(2) default'女',
7 EmployeeCellPhone int not null,
8 EmployeeAddress nvarchar(50),
9 EmployeeComments nvarchar(1000)
10 )
然后往这个表中插入数据(注:如果在源表中设置了标识符的,请在下面语句前加入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下创建表的语句放在另一个数据库destest下执行,这时,我们建立了一个表。再在这个数据库下执行以下语句:
insert destest.dbo.Employee (EmployeeID,EmployeeName,EmployeeAge,EmployeeSex,EmployeeCellPhone,EmployeeAddress,EmployeeComments)
select EmployeeID,EmployeeName,EmployeeAge,EmployeeSex,EmployeeCellPhone,EmployeeAddress,EmployeeComments
from soutest.dbo.Employee
至此,工作全部结束。