不明白你要什么,本身数据库就有缺陷

解决方案 »

  1.   

    原来的网站用了4个库,现在要合并成一个库,现在不是抱怨缺陷的问题,是要解决问题
      

  2.   

    你这样,工作量又大,又混乱,又容易遗露.个人建议.(随手敲的,难免手误)设原来的四个库为 db1,db2,db3,db4
    新库为 newDb
    db1下有 tb1,tb2,tb3
    db2下有 tb1,tb2,tb4
    db3下有 tb1,tb2,tb6
    db4下有 tb1,tb5,tb6设每个库下同名的表,结构是相同的, 比如 tb1代表usertable ,那么 db1..tb1就是某一范围的userTable.给newDb创建表 tb1,tb2,tb3,tb4,tb5,tb6.
    以tb1为例.
    老库 tb1 (id int identity(1,1), name varchar(20))
    那么 newDb..tb1结构为 (id int identity(1,1),oldid int, name varchar(20),fromDb int)
    id为 newDb中新建的tb1的标识列.
    oldid 为 某行在原库原表中的标识列
    fromDb 为 某行所在原表所在的库的编号use newDb
    insert tb1 (
        select id,name,1 from db1..tb1
        union all
        select id,name,2 from db2..tb1
        union all
        select id,name,3 from db3..tb1
        union all
        select id,name,4 from db4..tb1
        )
    完成了数据的导入
    以后在使用 newDb.tb1新插入数据时, 一律给fromDb值为0, 表示是新表中的,没有from记录
    当对原始数据查询时
    比如要实现原来这样的查询:
    use db1
    select * from tb1 where id=2
    那么可以改用
    use newdb
    select * from tb1 where fromDb=1 and oldid=2