管家婆普及版sql数据库如何导入366++版数据库
1、sql语句把一个表的某几列的数据存到另一稍僚敉视个表里的方法一.如何用slq语句把一个表中的某几个字段的数据插入到另一个新表中,就要用下面这条slq语句:insert into 表名1(字段1,字段2) select 字段1,字段2 from 表名2这里有一点值得注意的是这2个字段要一一对应,并且按顺序。二.如果另一个表是已经有数据的表,只希望更改其中的一列或几列的话,则用下面的sql语句:update 表名1,表名2 set 表名1.字段1 = 表名2.字段1 where 表名1.字段2 = 表名2.字段2因为第二个表是更新,所以只要指定与第一个表的关系,目的是数据的更新的时候能一一对应。SQLServer中把某个表里的记录复制到另一个数据库的表中 现有数据库a和数据库b,数据库a里有表table1,数据库b里有表table2. 现在要把表table1里的记录复制到table2中,不同情况采用不同方法:1. table1和table2表结构相同use binsert into table2 select * from a.dbo.table12. table1和table2表结构不相同use binsert into table2(c1,c2) select c1,c2 from a.dbo.table1coolxiaoyi:c1,c2为需要复制的列。3. 如果还没有创建表table2,可以直接将table1的表结构和记录都复制到数据库b中use b select * into table2 from a.dbo.table1coolxiaoyi:这样做有一个问题,就是有时主外键关系不能复制过去(不知道什么原因),需要在执行完sql语句后自己再设置一下主外键。4. 注意table2中是否有自增长字段 如果有自增长字段,使用以上sql语句时会报错:仅当使用了列列表并且 IDENTITY_INSERT 为 ON 时,才能为表'table2'中 的标识列指定显式值。 coolxiaoyi:可以先修改table2表,去掉自增长标识,复制完记录后再修改回来。 或者用2.中的sql语句,不复制自增长字段,复制其他字段。IDENTITY_INSERT 设置为 OFF 时,不能向表 'people' 中的标识列插入显式值。
2、根据上面的数据库语句,我需要将管家婆普及版2013tr的数据库导出到excel表。然后倒入tr2014管家婆辉煌366++数据字羿岚寺库。具体操作如下:2013excel数据表导入tryl2014数据库有37个表出现错误分别是:大概有数据的有:areatype atypecw btype goodsstocks inigoodsstocks ptype t_gbl_actionlist t_gbl_datatypelist t_gbl_fieldtypelist t_gbl_functionlist t_gbl_messagelist t_gbl_rightkind t_gbl_stringlist v_atypename v_atypewidz v_btypearap v_btypename v_btypeotherarap v_ptypecalc v_ptypename v_ptypename2 vchtype view_zz_vchbalance zerotype倒表语句实用存下:对照2013excel导出的所有表项。use tr2014set IDENTITY_INSERT areatype ONinsert into areatype(Leveal,SonNum,SonCount,UserCode,Name,FullName,Comment,Deleted,Rec,ParRec,namepy) select Leveal,SonNum,SonCount,UserCode,Name,FullName,Comment,Deleted,Rec,ParRec,namepy from 天润2013新.dbo.areatypeset IDENTITY_INSERT areatype offptype_index 一个主键 删掉索引后导入数据,然后在工具——管理索引重建一个索引use tr2014set IDENTITY_INSERT ptype ONinsert into ptype(typeId,ParId,leveal,sonnum,soncount,CanModify,UserCode,FullName,Name,Standard,Type,Area,Unit1,Unit2,UnitRate1,UnitRate2,preprice1,preprice2,preprice3,preprice4,UsefulLifeMonth,UsefulLifeDay,Comment,recPrice,deleted,costmode,Namepy,warnup,warndown,Rec,ParRec,barcode)select typeId,ParId,leveal,sonnum,soncount,CanModify,UserCode,FullName,Name,Standard,Type,Area,Unit1,Unit2,UnitRate1,UnitRate2,preprice1,preprice2,preprice3,preprice4,UsefulLifeMonth,UsefulLifeDay,Comment,recPrice,deleted,costmode,Namepy,warnup,warndown,Rec,ParRec,barcode from 天润2013新.dbo.ptypeset IDENTITY_INSERT ptype offgoodsstockindex 2个主键use tr2014xinsert into goodsstocks(PtypeId,KtypeId,JobNumber,OutFactoryDate,Qty,Price,Total,GoodsOrder)select PtypeId,KtypeId,JobNumber,OutFactoryDate,Qty,Price,Total,GoodsOrder from 天润2013新.dbo.goodsstocksuse tr2014xinsert into inigoodsstocks(PtypeId,KtypeId,JobNumber,OutFactoryDate,Qty,Price,Total,GoodsOrder)select PtypeId,KtypeId,JobNumber,OutFactoryDate,Qty,Price,Total,GoodsOrder from 天润2013新.dbo.inigoodsstocksbtypeidx 1个主键唯一索引use tr2014xset IDENTITY_INSERT btype ONinsert into btype(typeId,parid,leveal,soncount,sonnum,UserCode,FullName,Name,Area,TelAndAddress,PostCode,Person,TaxNumber,BankAndAcount,Comment,ARTotal,APTotal,ARTotal00,APTotal00,deleted,Namepy,Rec,ParRec,AreaTypeID,fax)select typeId,parid,leveal,soncount,sonnum,UserCode,FullName,Name,Area,TelAndAddress,PostCode,Person,TaxNumber,BankAndAcount,Comment,ARTotal,APTotal,ARTotal00,APTotal00,deleted,Namepy,Rec,ParRec,AreaTypeID,fax from 天润2013新.dbo.btypeset IDENTITY_INSERT btype offptype有唯一主键索引无法导入,删除索引ptype_index后导入,然后重建索引。下面的SQL语句对students表在sid上添加PRIMARY KEY索引。ALTER TABLE ptype ADD PRIMARY KEY (typeId)