首页 > 代码库 > 把一个数据库中的数据导入另一个数据库中

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

use mastergo-- =============================================-- Basic Create Database Template-- =============================================IF EXISTS (SELECT *        FROM   master..sysdatabases        WHERE  name = NlbNorthwind)    DROP DATABASE lbNorthwindGOCREATE DATABASE lbNorthwindGOuse lbNorthwindgocreate 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 categoriesgoCREATE 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.productsgo--select * from products

 

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