把一个数据库中的数据导入另一个数据库中

use master
go
-- =============================================
-- Basic Create Database Template
-- =============================================
IF EXISTS (SELECT * 
       FROM   master..sysdatabases 
       WHERE  name = NlbNorthwind)
    DROP DATABASE lbNorthwind
GO

CREATE DATABASE lbNorthwind
GO
use lbNorthwind
go
create table categories(
    categoryID int primary key IDENTITY (1, 1) NOT NULL ,
    categoryName nvarchar(15)  NOT NULL 
) 
GO
---从northwind库中导入数据
insert into categories(categoryname) select categoryname from northwind.dbo.categories
--select * from categories
go
CREATE TABLE [Products] (
    [ProductID] int primary key IDENTITY (1, 1) NOT NULL ,
    [ProductName] nvarchar (40) NOT NULL ,
    [CategoryID] int foreign key references categories(categoryid) ,
    [UnitPrice] money NULL DEFAULT (0),
)
GO
---从northwind库中导入数据
insert into products(productname,categoryid,unitprice) select productname,categoryid,unitprice from northwind.dbo.products
go
--select * from products

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。