Oracle 10g迁移到Sql Server 2005

1、在Sql Server2005中建立连接oracle的数据库链接,链接名称=ORCL1;

a)链接服务器:写上链接服务器的名字,如:Orcl1

b) 服务器类型,选择其他数据源

c) 访问接口:选择 Microsoft OLE DB Provider for Oracle

d) 产品名称:写上 Oracle

e) 数据源:写上tnsnames.ora 文件中配置的服务名,如:orcl1_devs_s2

f)访问接口字符串:MSDAORA

g)在选择安全性选项页,使用此安装上下文建立连接:

    1:远程登录:用户名

    2:使用密码:密码

h) 确定

g)直接在Sql Server2005中写查询语句:select * from [链接服务器名称]..[用户名].[表名](切忌表明要用大写)

2、在oracle数据库中获取所有用户表,通过下列语句:(中Oracle数据库中操作)
select 'select * into ' || TABLE_NAME || ' from ORCL1..SA.'||  TABLE_NAME ||';' from user_tables
可以获取到“select * into AUDITTRAIL from ORCL1..SA.AUDITTRAIL;”这样将数据插入到Sql Server 2005数据库的查询语句;

3、修改数据类型(中Sql Server 2005数据库中操作)
--数据类型的修改主要针对以下几种类型:
Number(38,10)-->float
Number(10,0)-->int
Number(1,0)-->bit
--float型、可空
SELECT 'ALTER TABLE ' + sys.tables.name + ' ALTER COLUMN ' + QUOTENAME(sys.columns.name) + ' float'
from sys.columns,sys.tables,sys.types
where sys.tables.object_id=sys.columns.object_id
and sys.types.user_type_id=sys.columns.user_type_id
and sys.tables.name in(select Name from sysobjects where xtype='U')
and sys.columns.is_nullable = 1
and sys.types.name = 'numeric'
and sys.columns.precision = 38
and sys.columns.scale = 10
--float型、不可空
SELECT 'ALTER TABLE ' + sys.tables.name + ' ALTER COLUMN ' + QUOTENAME(sys.columns.name) + ' float not null'
from sys.columns,sys.tables,sys.types
where sys.tables.object_id=sys.columns.object_id
and sys.types.user_type_id=sys.columns.user_type_id
and sys.tables.name in(select Name from sysobjects where xtype='U')
and sys.columns.is_nullable = 0
and sys.types.name = 'numeric'
and sys.columns.precision = 38
and sys.columns.scale = 10
--int型、可空
SELECT 'ALTER TABLE ' + sys.tables.name + ' ALTER COLUMN ' + QUOTENAME(sys.columns.name) + ' int'
from sys.columns,sys.tables,sys.types
where sys.tables.object_id=sys.columns.object_id
and sys.types.user_type_id=sys.columns.user_type_id
and sys.tables.name in(select Name from sysobjects where xtype='U')
and sys.columns.is_nullable = 1
and sys.types.name = 'numeric'
and sys.columns.precision = 10
and sys.columns.scale = 0
--int型、不可空
SELECT 'ALTER TABLE ' + sys.tables.name + ' ALTER COLUMN ' + QUOTENAME(sys.columns.name) + ' int not null'
from sys.columns,sys.tables,sys.types
where sys.tables.object_id=sys.columns.object_id
and sys.types.user_type_id=sys.columns.user_type_id
and sys.tables.name in(select Name from sysobjects where xtype='U')
and sys.columns.is_nullable = 0
and sys.types.name = 'numeric'
and sys.columns.precision = 10
and sys.columns.scale = 0
--bit型、不可空
SELECT 'ALTER TABLE ' + sys.tables.name + ' ALTER COLUMN ' + QUOTENAME(sys.columns.name) + ' bit not null'
from sys.columns,sys.tables,sys.types
where sys.tables.object_id=sys.columns.object_id
and sys.types.user_type_id=sys.columns.user_type_id
and sys.tables.name in(select Name from sysobjects where xtype='U')
--and sys.columns.is_nullable = 0
and sys.types.name = 'numeric'
and sys.columns.precision = 1
and sys.columns.scale = 0

4、主键约束
--通过sysobjects和syscolumns表来获取(中Sql Server 2005数据库中操作)
select distinct 'alter table ' + c.Name + ' ADD CONSTRAINT PK_' + c.Name + ' PRIMARY KEY CLUSTERED(' + a.Name + ')'
from syscolumns a, sysobjects c
--过滤用户表
where c.xtype = 'U'
--找到主键字段
and a.Name = 'ID'


5、导入外键(中Oracle数据库中操作)
select 'ALTER TABLE '
    || c.table_name
    || ' WITH CHECK ADD CONSTRAINT ['
    || c.constraint_name
    || '] FOREIGN KEY(['
    || c.column_name
    || ']) REFERENCES ['
    || b.table_name
    || '] (['
    || b.column_name
    || '])'
from
(select * from user_cons_columns) b
left  join
(select * from user_constraints
where user_constraints.constraint_type='R') a
on  b.constraint_name=a.r_constraint_name
left  join
user_cons_columns c
on  c.constraint_name=a.constraint_name
where c.position is not null
and c.position=b.position
order by b.table_name

ASP.NET开发技术交流群: 67511751(人员招募中...)

原文地址:https://www.cnblogs.com/Juvy/p/2159247.html