IF EXISTS (SELECT 1 FROM dbo.sysreferences r JOIN dbo.sysobjects o ON (o.id = r.constid AND o.type = 'F') WHERE r.fkeyid = object_id('TItemSub') AND o.name = 'FK_ITEM_ID') BEGIN ALTER TABLE TItemSub DROP CONSTRAINT FK_ITEM_ID END GO IF EXISTS (SELECT 1 FROM dbo.sysreferences r JOIN dbo.sysobjects o ON (o.id = r.constid AND o.type = 'F') WHERE r.fkeyid = object_id('TItemImage') AND o.name = 'FK_ITEM_IMAGE_ITEM_ID') BEGIN ALTER TABLE TItemImage DROP CONSTRAINT FK_ITEM_IMAGE_ITEM_ID END GO IF EXISTS (SELECT 1 FROM dbo.sysreferences r JOIN dbo.sysobjects o ON (o.id = r.constid AND o.type = 'F') WHERE r.fkeyid = object_id('TCourse') AND o.name = 'FK_COURSE_ITEM_ID') BEGIN ALTER TABLE TCourse DROP CONSTRAINT FK_COURSE_ITEM_ID END GO IF EXISTS (SELECT 1 FROM dbo.sysreferences r JOIN dbo.sysobjects o ON (o.id = r.constid AND o.type = 'F') WHERE r.fkeyid = object_id('TOrderItem') AND o.name = 'FK_ORDER_ITEM_ITEM_ID') BEGIN ALTER TABLE TOrderItem DROP CONSTRAINT FK_ORDER_ITEM_ITEM_ID END GO IF EXISTS (SELECT 1 FROM dbo.sysreferences r JOIN dbo.sysobjects o ON (o.id = r.constid AND o.type = 'F') WHERE r.fkeyid = object_id('TOrderItem') AND o.name = 'FK_ORDER_ITEM_ITEM_ID') BEGIN ALTER TABLE TOrderItem DROP CONSTRAINT FK_ORDER_ITEM_ITEM_ID END GO IF EXISTS (SELECT 1 FROM dbo.sysreferences r JOIN dbo.sysobjects o ON (o.id = r.constid AND o.type = 'F') WHERE r.fkeyid = object_id('TConsumeItem') AND o.name = 'FK_CONSUME_ITEM_ITEM_ID') BEGIN ALTER TABLE TConsumeItem DROP CONSTRAINT FK_CONSUME_ITEM_ITEM_ID END GO IF EXISTS (SELECT 1 FROM dbo.sysreferences r JOIN dbo.sysobjects o ON (o.id = r.constid AND o.type = 'F') WHERE r.fkeyid = object_id('TMemberCourse') AND o.name = 'FK_MEMBER_COURSE_ITEM_ID') BEGIN ALTER TABLE TMemberCourse DROP CONSTRAINT FK_MEMBER_COURSE_ITEM_ID END GO SELECT object_name(id) FROM syscolumns WHERE name like '%ItemId%' AND Id in(select id from sysobjects where type = 'U') SELECT A.FNo,A.FName,B.FName,C.FName,C.FNo FROM TaiYuan_ManJia..TItem AS A LEFT JOIN TaiYuan_ManJia_2..TItem AS B ON A.FNo = B.FNo AND A.FName != B.FName LEFT JOIN TaiYuan_ManJia_3..TItem AS C ON C.FNo = A.FNo AND A.FName != C.FName select * from TaiYuan_ManJia_3..TItem WHERE FNo = '104' USE TaiYuan_ManJia_3 ALTER TABLE TItem ADD FNewId BIGINT UPDATE B SET B.FNewId = A.FId FROM TItem AS B,TaiYuan_ManJia..TItem AS A WHERE A.FNo = B.FNo SELECT * FROM TItem WHERE FNewId IS NULL UPDATE B SET B.FItemId = A.FNewId FROM TItemSub AS B,TItem AS A WHERE A.FId = B.FItemId UPDATE B SET B.FItemId = A.FNewId FROM TCourse AS B,TItem AS A WHERE A.FId = B.FItemId UPDATE B SET B.FItemId = A.FNewId FROM TConsumeItem AS B,TItem AS A WHERE A.FId = B.FItemId UPDATE B SET B.FItemId = A.FNewId FROM TOrderItem AS B,TItem AS A WHERE A.FId = B.FItemId UPDATE B SET B.FContentId = A.FNewId FROM TMemberTransHist AS B,TItem AS A WHERE A.FId = B.FContentId UPDATE B SET B.FItemId = A.FNewId FROM TMemberCourse AS B,TItem AS A WHERE A.FId = B.FItemId UPDATE B SET B.FItemId = A.FNewId FROM TMemberCOurseLog AS B,TItem AS A WHERE A.FId = B.FItemId UPDATE B SET B.FItemId = A.FNewId FROM TConsumeReturnVisit AS B,TItem AS A WHERE A.FId = B.FItemId UPDATE B SET B.FItemId = A.FNewId FROM TItemDiscountMaster AS B,TItem AS A WHERE A.FId = B.FItemId UPDATE B SET B.FItemId = A.FNewId FROM TItemReturnVisit AS B,TItem AS A WHERE A.FId = B.FItemId UPDATE B SET B.FItemId = A.FNewId FROM TMemberCardTypeAllowItem AS B,TItem AS A WHERE A.FId = B.FItemId UPDATE B SET B.FItemId = A.FNewId FROM TMemberCardTypeFreeItem AS B,TItem AS A WHERE A.FId = B.FItemId UPDATE B SET B.FItemId = A.FNewId FROM TMemberOldTransHist AS B,TItem AS A WHERE A.FId = B.FItemId UPDATE TItem SET FId = FNewId ALTER TABLE TItem DROP COLUMN FNewId --²úÆ· SELECT object_name(id) FROM syscolumns WHERE name like '%GoodsId%' AND Id in(select id from sysobjects where type = 'U') SELECT A.FNo,A.FName,B.FName,C.FName,C.FNo FROM TaiYuan_ManJia..TGoods AS A LEFT JOIN TaiYuan_ManJia_2..TGoods AS B ON A.FNo = B.FNo AND A.FName != B.FName LEFT JOIN TaiYuan_ManJia_3..TGoods AS C ON C.FNo = A.FNo AND A.FName != C.FName select * from TaiYuan_ManJia_3..TItem WHERE FNo = '104' USE TaiYuan_ManJia_2 ALTER TABLE TGoods ADD FNewId BIGINT UPDATE B SET B.FNewId = A.FId FROM TGoods AS B,TaiYuan_ManJia..TGoods AS A WHERE A.FNo = B.FNo UPDATE B SET B.FGoodsId = A.FNewId FROM TGoodsSub AS B,TGoods AS A WHERE A.FId = B.FGoodsId UPDATE B SET B.FGoodsId = A.FNewId FROM TConsumeGoods AS B,TGoods AS A WHERE A.FId = B.FGoodsId UPDATE B SET B.FGoodsId = A.FNewId FROM TGoodsMultiUnit AS B,TGoods AS A WHERE A.FId = B.FGoodsId UPDATE B SET B.FGoodsId = A.FNewId FROM TOrderGoods AS B,TGoods AS A WHERE A.FId = B.FGoodsId UPDATE B SET B.FGoodsId = A.FNewId FROM TGoodsSub AS B,TGoods AS A WHERE A.FId = B.FGoodsId UPDATE B SET B.FGoodsId = A.FNewId FROM TGoodsBaseComm AS B,TGoods AS A WHERE A.FId = B.FGoodsId UPDATE B SET B.FContentId = A.FNewId FROM TMemberTransHist AS B,TGoods AS A WHERE A.FId = B.FContentId UPDATE TGoods SET FId = FNewId ALTER TABLE TGoods DROP COLUMN FNewId --¿¨Àà±ð SELECT object_name(id) FROM syscolumns WHERE name like '%CardTypeId%' AND Id in(select id from sysobjects where type = 'U') SELECT A.FId,B.FId,C.FId,A.FNo,A.FName,B.FName,C.FName,C.FNo FROM TaiYuan_ManJia..TMemberCardType AS A LEFT JOIN TaiYuan_ManJia_2..TMemberCardType AS B ON A.FNo = B.FNo AND A.FName != B.FName LEFT JOIN TaiYuan_ManJia_3..TMemberCardType AS C ON C.FNo = A.FNo AND A.FName != C.FName ALTER TABLE TMemberCardType ADD FNewId BIGINT UPDATE B SET B.FNewId = A.FId FROM TMemberCardType AS B,TaiYuan_ManJia..TMemberCardType AS A WHERE A.FNo = B.FNo UPDATE TMemberCardType SET FNewId = FId WHERE FNewId IS NULL UPDATE B SET B.FCardTypeId = A.FNewId FROM TMemberCardTypeSub AS B,TMemberCardType AS A WHERE A.FId = B.FCardTypeId UPDATE B SET B.FCardTypeId = A.FNewId FROM TMemberCardAcctHist AS B,TMemberCardType AS A WHERE A.FId = B.FCardTypeId UPDATE B SET B.FTypeId = A.FNewId FROM TMemberCard AS B,TMemberCardType AS A WHERE A.FId = B.FTypeId UPDATE B SET B.FCardTypeId = A.FNewId FROM TMemberCardTypeBaseComm AS B,TMemberCardType AS A WHERE A.FId = B.FCardTypeId UPDATE B SET B.FCardTypeId = A.FNewId FROM TMemberSaleCard AS B,TMemberCardType AS A WHERE A.FId = B.FCardTypeId UPDATE B SET B.FCardTypeId = A.FNewId FROM TConsumeItemPayment AS B,TMemberCardType AS A WHERE A.FId = B.FCardTypeId UPDATE B SET B.FCardTypeId = A.FNewId FROM TConsumeBill AS B,TMemberCardType AS A WHERE A.FId = B.FCardTypeId UPDATE B SET B.FContentId = A.FNewId FROM TMemberTransHist AS B,TMemberCardType AS A WHERE A.FId = B.FContentId UPDATE B SET B.FCardTypeId = A.FNewId FROM TMemberCardOldAcctHist AS B,TMemberCardType AS A WHERE A.FId = B.FCardTypeId UPDATE B SET B.FCardTypeId = A.FNewId FROM TItemDiscountMid AS B,TMemberCardType AS A WHERE A.FId = B.FCardTypeId UPDATE TMemberCardType SET FId = FNewId ALTER TABLE TMemberCardType DROP COLUMN FNewId -- EXEC PCopyTable 'TaiYuan_ManJia..TCompany','TCompany',' AND FId > 1' EXEC PCopyTable 'TaiYuan_ManJia..TItem','TItem',' AND FId > 0 AND FNo NOT IN(SELECT FNo FROM TaiYuan_ManJia..TItem)' EXEC PCopyTable 'TaiYuan_ManJia..TItemSub','TItemSub',' ' EXEC PCopyTable 'TaiYuan_ManJia..TGoods','TGoods',' AND FId > 0 AND FNo NOT IN(SELECT FNo FROM TaiYuan_ManJia..TGoods)' EXEC PCopyTable 'TaiYuan_ManJia..TGoodsSub','TGoodsSub',' ' EXEC PCopyTable 'TaiYuan_ManJia..TMemberCardType','TMemberCardType',' AND FId > 0 AND FNo NOT IN(SELECT FNo FROM TaiYuan_ManJia..TMemberCardType)' EXEC PCopyTable 'TaiYuan_ManJia..TMemberCardTypeSub','TMemberCardTypeSub',' ' UPDATE TEmployee SET FNo = FNo + '.003' EXEC PCopyTable 'TaiYuan_ManJia..TEmployee','TEmployee',' AND FId > 0' EXEC PCopyTable 'TaiYuan_ManJia..TEmployeeSub','TEmployeeSub',' ' SELECT * FROM TUser DELETE TUserAllowCompany WHERE FUserId IN(SELECT FId FROM TUser WHERE FDeleted = 1) DELETE TUserRole WHERE FUserId IN(SELECT FId FROM TUser WHERE FDeleted = 1) DELETE TUser WHERE FId IN(SELECT FId FROM TUser WHERE FDeleted = 1) EXEC PCopyTable 'TaiYuan_ManJia..TUser','TUser',' AND FId > 9' EXEC PCopyTable 'TaiYuan_ManJia..TUserAllowCompany','TUserAllowCompany',' ' EXEC PChangeCenterCompany '000' SELECT * FROM TaiYuan_ManJia..TGoods SELECT * FROM TGoods UPDATE A SET A.FCardNO = 'A' + A.FCardNo FROM TaiYuan_ManJia..TMemberCard AS A WHERE A.FCardNo IN(SELECT FCardNo FROM #Card) UPDATE A SET A.FMemNo = 'A' + A.FMemNo FROM TaiYuan_ManJia..TMember AS A WHERE A.FMemNo IN(SELECT FCardNo FROM #Card) UPDATE A SET A.FCardNO = 'B' + A.FCardNo FROM TaiYuan_ManJia_2..TMemberCard AS A WHERE A.FCardNo IN(SELECT FCardNo FROM #Card) UPDATE A SET A.FMemNo = 'B' + A.FMemNo FROM TaiYuan_ManJia_2..TMember AS A WHERE A.FMemNo IN(SELECT FCardNo FROM #Card) UPDATE A SET A.FCardNO = 'B' + A.FCardNo FROM TaiYuan_ManJia_3..TMemberCard AS A WHERE A.FCardNo IN(SELECT FCardNo FROM #Card) UPDATE A SET A.FMemNo = 'B' + A.FMemNo FROM TaiYuan_ManJia_3..TMember AS A WHERE A.FMemNo IN(SELECT FCardNo FROM #Card) UPDATE TMember SET FMemno = REPLACE(FMemNo,'B','C') WHERE FMemNo LIKE 'B%' UPDATE TMemberCard SET FCardNo = REPLACE(FCardNo,'B','C') WHERE FCardNo LIKE 'B%' SELECT FCardNo INTO #Card FROM ( SELECT FCardNo FROM TaiYuan_ManJia..TMemberCard UNION ALL SELECT FCardNo FROM TaiYuan_ManJia_2..TMemberCard UNION ALL SELECT FCardNo FROM TaiYuan_ManJia_3..TMemberCard ) AS A GROUP BY FCardNo HAVING(SUM(1) > 1) ) SELECT * FROM TaiYuan_ManJia_3..TMemberCard WHERE FCardNo IN(SELECT FCardNO FROM TaiYuan_ManJia_2 ..TMemberCard) SELECT * FROM TaiYuan_ManJia_3..TMemberCard WHERE FCardNo IN(SELECT FCardNO FROM TaiYuan_ManJia ..TMemberCard) UPDATE A SET A.FId = B.FId FROM TCourse AS A,TaiYuan_ManJia..TCourse AS B WHERE A.FItemId = B.FItemId UPDATE A SET A.FCourseId = B.FId FROM TMemberCourse AS A,TaiYuan_ManJia..TCourse AS B WHERE A.FItemId = B.FItemId UPDATE A SET A.FCourseId = B.FId FROM TMemberCourseLog AS A,TaiYuan_ManJia..TCourse AS B WHERE A.FItemId = B.FItemId EXEC PCopyTable 'TaiYuan_ManJia..TMember','TMember',' AND FMemId > 0 ' EXEC PCopyTable 'TaiYuan_ManJia..TMemberCard','TMemberCard',' AND FCardId > 0 ' EXEC PCopyTable 'TaiYuan_ManJia..TMemberCourse','TMemberCourse',' ' EXEC PCopyTable 'TaiYuan_ManJia..TMemberCourseLog','TMemberCourseLog',' ' EXEC PCopyTable 'TaiYuan_ManJia..TMemberCardAccount','TMemberCardAccount',' AND FCardId > 0 ' EXEC PCopyTable 'TaiYuan_ManJia..TMemberCardAcctHist','TMemberCardAcctHist',' AND FCardId > 0 ' EXEC PCopyTable 'TaiYuan_ManJia..TMemberEmployee','TMemberEmployee',' ' EXEC PCopyTable 'TaiYuan_ManJia..TMemberPhoto','TMemberPhoto',' ' EXEC PCopyTable 'TaiYuan_ManJia..TMemberPointHist','TMemberPointHist',' ' EXEC PCopyTable 'TaiYuan_ManJia..TMemberTransHist','TMemberTransHist',' ' EXEC PCopyTable 'TaiYuan_ManJia..TMemberTransHistPayment','TMemberTransHistPayment',' ' EXEC PCopyTable 'TaiYuan_ManJia..TMemberOldTransHist','TMemberOldTransHist',' ' EXEC PCopyTable 'TaiYuan_ManJia..TMemberCardOldAcctHist','TMemberCardOldAcctHist',' AND FCardId > 0 ' EXEC PCopyTable 'TaiYuan_ManJia..TMemberArrear','TMemberArrear',' ' EXEC PCopyTable 'TaiYuan_ManJia..TMemberArrearEmployee','TMemberArrearEmployee',' ' EXEC PCopyTable 'TaiYuan_ManJia..TConsumeBill','TConsumeBill',' ' EXEC PCopyTable 'TaiYuan_ManJia..TConsumeGoods','TConsumeGoods',' ' EXEC PCopyTable 'TaiYuan_ManJia..TConsumeGoodsEmployee','TConsumeGoodsEmployee',' ' EXEC PCopyTable 'TaiYuan_ManJia..TConsumeGoodsPayment','TConsumeGoodsPayment',' ' EXEC PCopyTable 'TaiYuan_ManJia..TConsumeItem','TConsumeItem',' ' EXEC PCopyTable 'TaiYuan_ManJia..TConsumeItemCostGoods','TConsumeItemCostGoods',' ' EXEC PCopyTable 'TaiYuan_ManJia..TConsumeItemEmployee','TConsumeItemEmployee',' ' EXEC PCopyTable 'TaiYuan_ManJia..TConsumeItemPayment','TConsumeItemPayment',' ' EXEC PCopyTable 'TaiYuan_ManJia..TConsumeReturnVisit','TConsumeReturnVisit',' ' EXEC PCopyTable 'TaiYuan_ManJia..TConsumeReturnVisitLog','TConsumeReturnVisitLog',' ' SELECT name FROM sysobjects WHERE name like 'TConsume%' SELECT name FROM sysobjects WHERE name like 'TMemberSale%' EXEC PCopyTable 'TaiYuan_ManJia..TMemberSaleBill','TMemberSaleBill',' ' EXEC PCopyTable 'TaiYuan_ManJia..TMemberSaleCard','TMemberSaleCard',' ' EXEC PCopyTable 'TaiYuan_ManJia..TMemberSaleCombo','TMemberSaleCombo',' ' EXEC PCopyTable 'TaiYuan_ManJia..TMemberSaleCourse','TMemberSaleCourse',' ' EXEC PCopyTable 'TaiYuan_ManJia..TMemberSaleCoursePack','TMemberSaleCoursePack',' ' EXEC PCopyTable 'TaiYuan_ManJia..TMemberSaleCourseGoods','TMemberSaleCourseGoods',' ' EXEC PCopyTable 'TaiYuan_ManJia..TMemberSaleDetailPayment','TMemberSaleDetailPayment',' ' EXEC PCopyTable 'TaiYuan_ManJia..TMemberSaleDetailSplit','TMemberSaleDetailSplit',' ' EXEC PCopyTable 'TaiYuan_ManJia..TMemberSaleEmployee','TMemberSaleEmployee',' ' EXEC PCopyTable 'TaiYuan_ManJia..TMemberSaleExchange','TMemberSaleExchange',' ' EXEC PCopyTable 'TaiYuan_ManJia..TMemberSaleExchangeSource','TMemberSaleExchangeSource',' ' EXEC PCopyTable 'TaiYuan_ManJia..TMemberSaleFreeItem','TMemberSaleFreeItem',' ' EXEC PCopyTable 'TaiYuan_ManJia..TMemberSaleInfo','TMemberSaleInfo',' ' EXEC PCopyTable 'TaiYuan_ManJia..TMemberSalePayment','TMemberSalePayment',' ' EXEC PCopyTable 'TaiYuan_ManJia..TMemberSaleRepay','TMemberSaleRepay',' ' SELECT * FROM TPayAccount WHERE FId = 5639249224514336917 SELECT * FROM TMemberCardAccount WHERE FAcctId = 5639249224514336917 DELETE TMemberCardaCCTHIST WHERE FAcctId = 5639249224514336917