1 表结构生成sql脚本
在指定的表【bjgl_code】(以下均以bjgl_code为例)上点击右键,选择【所有任务】-》【生成sql脚本】,在右下角的【将要写入脚本的对象】中选择bjgl_code,
点击【选项】选项卡,勾选【表脚本选项】的所有选项。【文件选项】选择【windows文本】,因为我的编辑器是gvim,文件编码utf8,如果使用默认的国际化unicode,会导致显示异常。原因暂时不知道。其它的默认设置即可,点击确定,选择生成文件的目录和文件名即可,我选则的table1.sql 。内容如下:
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bjgl_code1]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bjgl_code1]
GO
/****** Object: Table [dbo].[bjgl_code1] Script Date: 2016/12/2 15:58:02 ******/
CREATE TABLE [dbo].[bjgl_code1] (
[code_id] [int] IDENTITY (1, 1) NOT NULL ,
[code_type] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
[code_type_name] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
[code_value] [int] NULL ,
[code_info] [varchar] (40) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[bjgl_code1] WITH NOCHECK ADD
PRIMARY KEY CLUSTERED
(
[code_id]
) ON [PRIMARY]
GO
CREATE INDEX [bjgl_code_code_type] ON [dbo].[bjgl_code1]([code_type]) ON [PRIMARY]
GO
基本上常用的元素都齐了。
2 导出表中的数据内容
在指定的表【bjgl_code】(以下均以bjgl_code为例)上点击右键,选择【所有任务】-》【导出数据】,【下一步】,再点【下一步】,
在【目的】步骤选择【文本文件】,然后填写文件名和目录,我填的是content.txt,点击【下一步】,在【指定表复制或查询】中,可以复制全部内容,或者使用select语句指定复制内容
我这里选择了第一项复制全部内容,后面的就是下一步或者确定了。生成的文件内容大致如下:
1,"meter_status","计量器具状态",1,"库存"
2,"meter_status","计量器具状态",2,"退货"
3,"meter_status","计量器具状态",3,"领用"
4,"meter_status","计量器具状态",4,"报废"
5,"operation_content","作业内容",1,"修改"
6,"operation_content","作业内容",2,"删除"
7,"operation_content","作业内容",3,"入库(新增)"
8,"operation_content","作业内容",4,"入库(回收)"
9,"operation_content","作业内容",5,"退货"
10,"operation_content","作业内容",6,"出库领用"
11,"operation_content","作业内容",7,"出库取消"
12,"operation_content","作业内容",8,"报废"
13,"operation_content","作业内容",9,"报废取消"
15,"in_source","入库来源",1,"手动入库"
16,"in_source","入库来源",2,"扫描枪入库"
17,"out_mode","出库方式",1,"单个出库"
18,"out_mode","出库方式",2,"整箱出库"
19,"meter_maker","计量器具厂家",1,"万泰公司"
20,"meter_maker","计量器具厂家",2,"德源电子"
21,"meter_model","计量器具型号",1,"电表"
22,"meter_model","计量器具型号",2,"互感器"
23,"meter_spec","计量器具规格",1,"单相 10(40)A"
24,"meter_spec","计量器具规格",2,"三相 1.5(6)A"
25,"meter_warehouse","计量器具仓库",1,"一号仓库"
26,"meter_warehouse","计量器具仓库",2,"二号仓库"
27,"operation_content","作业内容",10,"校验首次入库"
28,"operation_content","作业内容",11,"校验二次入库"
3.使用sql脚本创建表结构
把步骤1生成的文件table1.sql的内容放在查询分析器里运行,当然,要把表名改一下,因为数据库中原来已经存在bjgl_code了,可以改为bjgl_code1.这样就在数据库中创建了
新表bjgl_code1,结构和bjgl_code一模一样。
4把外部的文本数据导入表中
这里我使用步骤2生成的文件content.txt,因为这是bjgl_code的数据内容,刚好和bjgl_code1结构一致,可以导入到bjgl_code1中。
在bjgl_code1上右键选择【所有任务】-》【导出数据】,【下一步】,在【选择数据源】中,选择【文本文件】,把要用的文件和路径填入,我这里是桌面content.txt,然后就一路的下一步,在【选择源表和视图】的页面,把目的表设置为你想位置为之导入数据的表,我这里选择system_manager.dbo.bjgl_code1,然后是一路下一步。
最后点【完成】。这时候,你会看到bjgl_code1中已经包含了和bjgl_code一样的数据