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

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

 

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

上一篇:mysql笔记----哈希索引优缺点


下一篇:关于SQL中Between语句查询日期的问题