- 浏览: 15028 次
- 性别:
- 来自: 深圳
最新评论
-
yun_hua_yu:
看了maven 和guice部分 是想学学
java工作笔记一 Maven,Guice , Mena的简单使用 ,Eclipse必会快捷键 -
tian583391571:
有什么不对的,请指出.
struts学习笔记二:国际化和拦截器
背景:周一网站评审结束的时候,我提出了一个小问题,前台的地域问题没解决好,是因为获得的数据库的数据有问题,然后领导让我带着他看了源数据库,地域有的没有,有的也有些不规范,点播了一些关于数据统一和有效性的建议,我二话没说,想着重新进行一次数据库的设计和数据迁移。经过将近三天的辛苦奋战,终于重构了一次数据库还有成功的去掉了数据库中的一些无效的数据,重复的数据,还有修正了地域字段,写了大量的sql语句,想着温故而知新,所以有了这边总结性的笔记。按照过程的先后顺序,记录下一些要点,算是对自己的提高。
1. 建中转库和表。
这里没什么可说的,我觉得比较有用的一点就是判断数据中是否存在数据库或者表,
--判断数据库是否存在,不存在就创建(默认路径下)然后切换到创建的数据库来
If not exists (select * from master.dbo.sysdababases where name=’数据库名’)
Create database 数据库名
Use 数据库名
--判断表是否存在,存在就删除然后重新创建
--注意这里的uniqueidentifier类型,可产生32位的不重复的字符串,一般用来标识列,--插入的时候用newID()方法
If exists (select * from sysobjects where id=object_id(‘表名’) and type=’u’)
Drop table 表名
Create table Provincial(pid uniqueidentifier , province varchar(50), primary key (pid) )
2.迁移数据的存储过程
这里先要介绍下源数据库的结构,源数据库从最终目的来看主要存放的两个表的数据,但是为了某些目的,实际分成了很多表,其中有一个表,记录了这个实际的表存放的表名,比如说存放了A表和B表,现在我这么存放,把A的数据分成若干表,每个表存放1W条数据,有20张,A1,A2…,A20, 把B的数据分成若干表,每个表存放2W条数据,有10张,B1,B2…,B20,还有另外一张表AB,存放的是存放数据的表名(tb_name)。实际上我的迁移过程是通过分析这张表的结构来之后精心设计的。主要用到游标。
--思路:1,首先从AB中找出所有的同构表名。
--2,使用游标取出一个表名,通过字符串拼接的方法,拼接成一个数据迁移的sql语句,--然后执行sql语句。
--3.游标循环,执行所有表的数据迁移。
Go
Create procedure transferdata
As
Declare mycursor cursor for
Select tb_name from AB where tb_name like ‘%A%’
Open mycusor
Declare @tableStr varchar(100)
Delare @sourceDB varchar(100)
Set @sourceDB=’源数据库名.dbo.’
Delare @targetDB varchar(100)
Set @targetDB =’目标数据库名.dbo.A’
Declare @sql varchar(1000)
Fetch next from mycursor into @tableStr
While(@@fetch_status=0)
Begin
Set @sql=N’insert into ’+@targetDB+’ (id,name,sex,address) select newID(),tname,tsex,taddress from ’+@sourceDB+@tableStr
--执行文本的sql语句
Exec sp_executesql @sql
Fetch next from mycursor into @tableStr
End
Close mycursor
Deallocate mycursor
Exec transferdata
3.去掉无效的,重复的,修正地域字段的过程。
--去掉无效的数据(长度小于三的和含有数字或者字母的)
Delete from A where len(Ltrim(Rtrim(city)))<=3 or patindex(‘[A-Z,a-z,0-9]’,city)>0
--去掉重复的数据,只保留一条ID最小的,根据一个字段name来判断
Delete from A where name in (select name from A group by name having count(name)>1) and id not in (select min(convert(varchar(50),id)) from A group by name having count(name)>1))
--去掉重复的数据,只保留id最大的一条,根据多个字段来判断。
Delete A from A a
Where exists(select * from A where name=a.name and address=a.address and id>a.id)
--修正地域字段,假设地域字段都有值,不过不规范,现在要做的事情就是把它们修正为规--范的省份或者城市,至于找不到的就修正为中国。
If exists (select * from dbo.sysobjects where id=object_id(‘modifyRegion’) and objectproperty(id,N’modifyRegion’)=1)
Drop procedure modifyRegion
Go
Create procedure modifyRegion
As
Declare regioncursor cursor for
Select distinct city from A
Open regioncursor
Declare @regionItem nvarchar(50)
Fetch next from regioncursor into @regionItem
While(@@fetch_status=0)
Begin
--先判断省份是为了处理省市同名的取大的一定对。
If exists(select provincial from Provincial where provincial like ‘%’+@regionItem+’%’ )
Update A set city=( select min(provincial) from Provincial where provincial like ‘%’+@regionItem+’%’) where city=@regionItem
Else if exists (select city from City where city like ‘%’+@regionItem+’%’ )
Update A set city=( select min(city) from City where city like ‘%’+@regionItem+’%’) where city=@regionItem
Else
Update A set city=’中国’ where city=@regionItem
Fetch next from regioncursor into @regionItem
end
close regioncursor
deallocate regioncursor
go
exec modifyRegion
4.分享一个中国城市和省份的有用资料。
这是我无意中找到的,常用的资料,大家可以看看。
--省级 Provincial
--城市 City
create table Provincial(pid int,Provincial varchar(50),primary key (pid))
insert into Provincial values(1,'北京市')
insert into Provincial values(2,'天津市')
insert into Provincial values(3,'上海市')
insert into Provincial values(4,'重庆市')
insert into Provincial values(5,'河北省')
insert into Provincial values(6,'山西省')
insert into Provincial values(7,'台湾省')
insert into Provincial values(8,'辽宁省')
insert into Provincial values(9,'吉林省')
insert into Provincial values(10,'黑龙江省')
insert into Provincial values(11,'江苏省')
insert into Provincial values(12,'浙江省')
insert into Provincial values(13,'安徽省')
insert into Provincial values(14,'福建省')
insert into Provincial values(15,'江西省')
insert into Provincial values(16,'山东省')
insert into Provincial values(17,'河南省')
insert into Provincial values(18,'湖北省')
insert into Provincial values(19,'湖南省')
insert into Provincial values(20,'广东省')
insert into Provincial values(21,'甘肃省')
insert into Provincial values(22,'四川省')
insert into Provincial values(23,'贵州省')
insert into Provincial values(24,'海南省')
insert into Provincial values(25,'云南省')
insert into Provincial values(26,'青海省')
insert into Provincial values(27,'陕西省')
insert into Provincial values(28,'广西壮族自治区')
insert into Provincial values(29,'西藏自治区')
insert into Provincial values(30,'宁夏回族自治区')
insert into Provincial values(31,'新疆维吾尔自治区')
insert into Provincial values(32,'内蒙古自治区')
insert into Provincial values(33,'澳门特别行政区')
insert into Provincial values(34,'香港特别行政区')
--select pid,Provincial from Provincial
create table City(cid int not null,city varchar(50) primary key,pid int foreign key references Provincial(pid))
----------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------
--插入各个省的城市数据
--4个直辖市
insert into City values(1,'北京市',1)
insert into City values(1,'天津市',2)
insert into City values(1,'上海市',3)
insert into City values(1,'重庆市',4)
--select * from City where pid=4
----------------------------------------------------------------
--5河北省 11个地级市
insert into City values(1,'石家庄市',5)
insert into City values(2,'唐山市',5)
insert into City values(3,'秦皇岛市',5)
insert into City values(4,'邯郸市',5)
insert into City values(5,'邢台市',5)
insert into City values(6,'保定市',5)
insert into City values(7,'张家口市',5)
insert into City values(8,'承德市',5)
insert into City values(9,'沧州市',5)
insert into City values(10,'廊坊市',5)
insert into City values(11,'衡水市',5)
--select * from City where pid=5 order by cid
----------------------------------------------------------------
--6山西省 11个城市
insert into City values(1,'太原市',6)
insert into City values(2,'大同市',6)
insert into City values(3,'阳泉市',6)
insert into City values(4,'长治市',6)
insert into City values(5,'晋城市',6)
insert into City values(6,'朔州市',6)
insert into City values(7,'晋中市',6)
insert into City values(8,'运城市',6)
insert into City values(9,'忻州市',6)
insert into City values(10,'临汾市',6)
insert into City values(11,'吕梁市',6)
--select * from City where pid=6 order by cid
----------------------------------------------------------------
--7台湾省(台湾本岛和澎湖共设7市、16县,其中台北市和高雄市为“院辖市”,直属“行政院”,其余属台湾省;市下设区,县下设市(县辖市)、镇、乡,合称区市镇乡。)
insert into City values(1,'台北市',7)
insert into City values(2,'高雄市',7)
insert into City values(3,'基隆市',7)
insert into City values(4,'台中市',7)
insert into City values(5,'台南市',7)
insert into City values(6,'新竹市',7)
insert into City values(7,'嘉义市',7)
insert into City values(8,'台北县',7)
insert into City values(9,'宜兰县',7)
insert into City values(10,'桃园县',7)
insert into City values(11,'新竹县',7)
insert into City values(12,'苗栗县',7)
insert into City values(13,'台中县',7)
insert into City values(14,'彰化县',7)
insert into City values(15,'南投县',7)
insert into City values(16,'云林县',7)
insert into City values(17,'嘉义县',7)
insert into City values(18,'台南县',7)
insert into City values(19,'高雄县',7)
insert into City values(20,'屏东县',7)
insert into City values(21,'澎湖县',7)
insert into City values(22,'台东县',7)
insert into City values(23,'花莲县',7)
--select * from City where pid=7 order by cid
----------------------------------------------------------------
--8辽宁省 14个地级市
insert into City values(1,'沈阳市',8)
insert into City values(2,'大连市',8)
insert into City values(3,'鞍山市',8)
insert into City values(4,'抚顺市',8)
insert into City values(5,'本溪市',8)
insert into City values(6,'丹东市',8)
insert into City values(7,'锦州市',8)
insert into City values(8,'营口市',8)
insert into City values(9,'阜新市',8)
insert into City values(10,'辽阳市',8)
insert into City values(11,'盘锦市',8)
insert into City values(12,'铁岭市',8)
insert into City values(13,'朝阳市',8)
insert into City values(14,'葫芦岛市',8)
--select * from City where pid=8 order by cid
----------------------------------------------------------------
--9吉林省(2006年,辖:8个地级市、1个自治州;20个市辖区、20个县级市、17个县、3个自治县。)
insert into City values(1,'长春市',9)
insert into City values(2,'吉林市',9)
insert into City values(3,'四平市',9)
insert into City values(4,'辽源市',9)
insert into City values(5,'通化市',9)
insert into City values(6,'白山市',9)
insert into City values(7,'松原市',9)
insert into City values(8,'白城市',9)
insert into City values(9,'延边朝鲜族自治州',9)
--select * from City where pid=9 order by cid
----------------------------------------------------------------
--10黑龙江省(2006年,辖:12地级市、1地区;64市辖区、18县级市、45县、1自治县)
insert into City values(1,'哈尔滨市',10)
insert into City values(2,'齐齐哈尔市',10)
insert into City values(3,'鹤 岗 市',10)
insert into City values(4,'双鸭山市',10)
insert into City values(5,'鸡 西 市',10)
insert into City values(6,'大 庆 市',10)
insert into City values(7,'伊 春 市',10)
insert into City values(8,'牡丹江市',10)
insert into City values(9,'佳木斯市',10)
insert into City values(10,'七台河市',10)
insert into City values(11,'黑 河 市',10)
insert into City values(12,'绥 化 市',10)
insert into City values(13,'大兴安岭地区',10)
--select * from City where pid=10 order by cid
----------------------------------------------------------------
--11江苏省(2005年辖:13个地级市;54个市辖区、27个县级市、25个县)
insert into City values(1,'南京市',11)
insert into City values(2,'无锡市',11)
insert into City values(3,'徐州市',11)
insert into City values(4,'常州市',11)
insert into City values(5,'苏州市',11)
insert into City values(6,'南通市',11)
insert into City values(7,'连云港市',11)
insert into City values(8,'淮安市',11)
insert into City values(9,'盐城市',11)
insert into City values(10,'扬州市',11)
insert into City values(11,'镇江市',11)
insert into City values(12,'泰州市',11)
insert into City values(13,'宿迁市',11)
--select * from City where pid=11 order by cid
----------------------------------------------------------------
--12浙江省(2006年,辖:11个地级市;32个市辖区、22个县级市、35个县、1个自治县。)
insert into City values(1,'杭州市',12)
insert into City values(2,'宁波市',12)
insert into City values(3,'温州市',12)
insert into City values(4,'嘉兴市',12)
insert into City values(5,'湖州市',12)
insert into City values(6,'绍兴市',12)
insert into City values(7,'金华市',12)
insert into City values(8,'衢州市',12)
insert into City values(9,'舟山市',12)
insert into City values(10,'台州市',12)
insert into City values(11,'丽水市',12)
--select * from City where pid=12 order by cid
----------------------------------------------------------------
--13安徽省(2005年辖:17个地级市;44个市辖区、5县个级市、56个县。)
insert into City values(1,'合肥市',13)
insert into City values(2,'芜湖市',13)
insert into City values(3,'蚌埠市',13)
insert into City values(4,'淮南市',13)
insert into City values(5,'马鞍山市',13)
insert into City values(6,'淮北市',13)
insert into City values(7,'铜陵市',13)
insert into City values(8,'安庆市',13)
insert into City values(9,'黄山市',13)
insert into City values(10,'滁州市',13)
insert into City values(11,'阜阳市',13)
insert into City values(12,'宿州市',13)
insert into City values(13,'巢湖市',13)
insert into City values(14,'六安市',13)
insert into City values(15,'亳州市',13)
insert into City values(16,'池州市',13)
insert into City values(17,'宣城市',13)
--select * from City where pid=13 order by cid
----------------------------------------------------------------
--14福建省(2006年辖:9个地级市;26个市辖区、14个县级市、45个县。)
insert into City values(1,'福州市',14)
insert into City values(2,'厦门市',14)
insert into City values(3,'莆田市',14)
insert into City values(4,'三明市',14)
insert into City values(5,'泉州市',14)
insert into City values(6,'漳州市',14)
insert into City values(7,'南平市',14)
insert into City values(8,'龙岩市',14)
insert into City values(9,'宁德市',14)
--select * from City where pid=14 order by cid
----------------------------------------------------------------
--15江西省(2006年全省辖:11个地级市;19个市辖区、10个县级市、70个县。)
insert into City values(1,'南昌市',15)
insert into City values(2,'景德镇市',15)
insert into City values(3,'萍乡市',15)
insert into City values(4,'九江市',15)
insert into City values(5,'新余市',15)
insert into City values(6,'鹰潭市',15)
insert into City values(7,'赣州市',15)
insert into City values(8,'吉安市',15)
insert into City values(9,'宜春市',15)
insert into City values(10,'抚州市',15)
insert into City values(11,'上饶市',15)
--select * from City where pid=15 order by cid
----------------------------------------------------------------
--16山东省(2005年,辖:17个地级市;49个市辖区、31个县级市、60个县。)
insert into City values(1,'济南市',16)
insert into City values(2,'青岛市',16)
insert into City values(3,'淄博市',16)
insert into City values(4,'枣庄市',16)
insert into City values(5,'东营市',16)
insert into City values(6,'烟台市',16)
insert into City values(7,'潍坊市',16)
insert into City values(8,'济宁市',16)
insert into City values(9,'泰安市',16)
insert into City values(10,'威海市',16)
insert into City values(11,'日照市',16)
insert into City values(12,'莱芜市',16)
insert into City values(13,'临沂市',16)
insert into City values(14,'德州市',16)
insert into City values(15,'聊城市',16)
insert into City values(16,'滨州市',16)
insert into City values(17,'菏泽市',16)
--select * from City where pid=16 order by cid
----------------------------------------------------------------
--17河南省 17个地级市
insert into City values(1,'郑州市',17)
insert into City values(2,'开封市',17)
insert into City values(3,'洛阳市',17)
insert into City values(4,'平顶山市',17)
insert into City values(5,'安阳市',17)
insert into City values(6,'鹤壁市',17)
insert into City values(7,'新乡市',17)
insert into City values(8,'焦作市',17)
insert into City values(9,'濮阳市',17)
insert into City values(10,'许昌市',17)
insert into City values(11,'漯河市',17)
insert into City values(12,'三门峡市',17)
insert into City values(13,'南阳市',17)
insert into City values(14,'商丘市',17)
insert into City values(15,'信阳市',17)
insert into City values(16,'周口市',17)
insert into City values(17,'驻马店市',17)
insert into City values(18,'济源市',17)
--select * from City where pid=17 order by cid
----------------------------------------------------------------
--18湖北省(截至2005年12月31日,全省辖13个地级单位(12个地级市、1个自治州);102县级单位(38个市辖区、24个县级市、37个县、2个自治县、1个林区),共有1220个乡级单位(277个街道、733个镇、210个乡)。)
insert into City values(1,'武汉市',18)
insert into City values(2,'黄石市',18)
insert into City values(3,'十堰市',18)
insert into City values(4,'荆州市',18)
insert into City values(5,'宜昌市',18)
insert into City values(6,'襄樊市',18)
insert into City values(7,'鄂州市',18)
insert into City values(8,'荆门市',18)
insert into City values(9,'孝感市',18)
insert into City values(10,'黄冈市',18)
insert into City values(11,'咸宁市',18)
insert into City values(12,'随州市',18)
insert into City values(13,'仙桃市',18)
insert into City values(14,'天门市',18)
insert into City values(15,'潜江市',18)
insert into City values(16,'神农架林区',18)
insert into City values(17,'恩施土家族苗族自治州',18)
--select * from City where pid=18 order by cid
----------------------------------------------------------------
--19湖南省(2005年辖:13个地级市、1个自治州;34个市辖区、16个县级市、65个县、7个自治县。)
insert into City values(1,'长沙市',19)
insert into City values(2,'株洲市',19)
insert into City values(3,'湘潭市',19)
insert into City values(4,'衡阳市',19)
insert into City values(5,'邵阳市',19)
insert into City values(6,'岳阳市',19)
insert into City values(7,'常德市',19)
insert into City values(8,'张家界市',19)
insert into City values(9,'益阳市',19)
insert into City values(10,'郴州市',19)
insert into City values(11,'永州市',19)
insert into City values(12,'怀化市',19)
insert into City values(13,'娄底市',19)
insert into City values(14,'湘西土家族苗族自治州',19)
--select * from City where pid=19 order by cid
----------------------------------------------------------------
--20广东省(截至2005年12月31日,广东省辖:21个地级市,54个市辖区、23个县级市、41个县、3个自治县,429个街道办事处、1145个镇、4个乡、7个民族乡。)
insert into City values(1,'广州市',20)
insert into City values(2,'深圳市',20)
insert into City values(3,'珠海市',20)
insert into City values(4,'汕头市',20)
insert into City values(5,'韶关市',20)
insert into City values(6,'佛山市',20)
insert into City values(7,'江门市',20)
insert into City values(8,'湛江市',20)
insert into City values(9,'茂名市',20)
insert into City values(10,'肇庆市',20)
insert into City values(11,'惠州市',20)
insert into City values(12,'梅州市',20)
insert into City values(13,'汕尾市',20)
insert into City values(14,'河源市',20)
insert into City values(15,'阳江市',20)
insert into City values(16,'清远市',20)
insert into City values(17,'东莞市',20)
insert into City values(18,'中山市',20)
insert into City values(19,'潮州市',20)
insert into City values(20,'揭阳市',20)
insert into City values(21,'云浮市',20)
--select * from City where pid=20 order by cid
----------------------------------------------------------------
--21甘肃省 12个地级市、2个自治州
insert into City values(1,'兰州市',21)
insert into City values(2,'金昌市',21)
insert into City values(3,'白银市',21)
insert into City values(4,'天水市',21)
insert into City values(5,'嘉峪关市',21)
insert into City values(6,'武威市',21)
insert into City values(7,'张掖市',21)
insert into City values(8,'平凉市',21)
insert into City values(9,'酒泉市',21)
insert into City values(10,'庆阳市',21)
insert into City values(11,'定西市',21)
insert into City values(12,'陇南市',21)
insert into City values(13,'临夏回族自治州',21)
insert into City values(14,'甘南藏族自治州',21)
--select * from City where pid=21 order by cid
----------------------------------------------------------------
--22四川省18个地级市、3个自治州
insert into City values(1,'成都市',22)
insert into City values(2,'自贡市',22)
insert into City values(3,'攀枝花市',22)
insert into City values(4,'泸州市',22)
insert into City values(5,'德阳市',22)
insert into City values(6,'绵阳市',22)
insert into City values(7,'广元市',22)
insert into City values(8,'遂宁市',22)
insert into City values(9,'内江市',22)
insert into City values(10,'乐山市',22)
insert into City values(11,'南充市',22)
insert into City values(12,'眉山市',22)
insert into City values(13,'宜宾市',22)
insert into City values(14,'广安市',22)
insert into City values(15,'达州市',22)
insert into City values(16,'雅安市',22)
insert into City values(17,'巴中市',22)
insert into City values(18,'资阳市',22)
insert into City values(19,'阿坝藏族羌族自治州',22)
insert into City values(20,'甘孜藏族自治州',22)
insert into City values(21,'凉山彝族自治州',22)
--select * from City where pid=22 order by cid
----------------------------------------------------------------
--23贵州省(2006年辖:4个地级市、2个地区、3个自治州;10个市辖区、9个县级市、56个县、11个自治县、2个特区。)
insert into City values(1,'贵阳市',23)
insert into City values(2,'六盘水市',23)
insert into City values(3,'遵义市',23)
insert into City values(4,'安顺市',23)
insert into City values(5,'铜仁地区',23)
insert into City values(6,'毕节地区',23)
insert into City values(7,'黔西南布依族苗族自治州',23)
insert into City values(8,'黔东南苗族侗族自治州',23)
insert into City values(9,'黔南布依族苗族自治州',23)
--select * from City where pid=23 order by cid
----------------------------------------------------------------
--24海南省全省有2个地级市,6个县级市,4个县,6个民族自治县,4个市辖区,1个办事处(西南中沙群岛办事处 ,县级)。)
insert into City values(1,'海口市',24)
insert into City values(2,'三亚市',24)
insert into City values(3,'五指山市',24)
insert into City values(4,'琼海市',24)
insert into City values(5,'儋州市',24)
insert into City values(6,'文昌市',24)
insert into City values(7,'万宁市',24)
insert into City values(8,'东方市',24)
insert into City values(9,'澄迈县',24)
insert into City values(10,'定安县',24)
insert into City values(11,'屯昌县',24)
insert into City values(12,'临高县',24)
insert into City values(13,'白沙黎族自治县',24)
insert into City values(14,'昌江黎族自治县',24)
insert into City values(15,'乐东黎族自治县',24)
insert into City values(16,'陵水黎族自治县',24)
insert into City values(17,'保亭黎族苗族自治县',24)
insert into City values(18,'琼中黎族苗族自治县',24)
--select * from City where pid=24 order by cid
----------------------------------------------------------------
--25云南省(2006年辖:8个地级市、8个自治州;12个市辖区、9个县级市、79个县、29个自治县。)
insert into City values(1,'昆明市',25)
insert into City values(2,'曲靖市',25)
insert into City values(3,'玉溪市',25)
insert into City values(4,'保山市',25)
insert into City values(5,'昭通市',25)
insert into City values(6,'丽江市',25)
insert into City values(7,'思茅市',25)
insert into City values(8,'临沧市',25)
insert into City values(9,'文山壮族苗族自治州',25)
insert into City values(10,'红河哈尼族彝族自治州',25)
insert into City values(11,'西双版纳傣族自治州',25)
insert into City values(12,'楚雄彝族自治州',25)
insert into City values(13,'大理白族自治州',25)
insert into City values(14,'德宏傣族景颇族自治州',25)
insert into City values(15,'怒江傈傈族自治州',25)
insert into City values(16,'迪庆藏族自治州',25)
--select * from City where pid=25 order by cid
----------------------------------------------------------------
--26青海省(2006年辖:1个地级市、1个地区、6个自治州;4个市辖区、2个县级市、30个县、7个自治县。)
insert into City values(1,'西宁市',26)
insert into City values(2,'海东地区',26)
insert into City values(3,'海北藏族自治州',26)
insert into City values(4,'黄南藏族自治州',26)
insert into City values(5,'海南藏族自治州',26)
insert into City values(6,'果洛藏族自治州',26)
insert into City values(7,'玉树藏族自治州',26)
insert into City values(8,'海西蒙古族藏族自治州',26)
--select * from City where pid=26 order by cid
----------------------------------------------------------------
--27陕西省(2006年辖:10个地级市;24个市辖区、3个县级市、80个县。)
insert into City values(1,'西安市',27)
insert into City values(2,'铜川市',27)
insert into City values(3,'宝鸡市',27)
insert into City values(4,'咸阳市',27)
insert into City values(5,'渭南市',27)
insert into City values(6,'延安市',27)
insert into City values(7,'汉中市',27)
insert into City values(8,'榆林市',27)
insert into City values(9,'安康市',27)
insert into City values(10,'商洛市',27)
--select * from City where pid=27 order by cid
----------------------------------------------------------------
--28广西壮族自治区(2005年辖:14个地级市;34个市辖区、7个县级市、56个县、12个自治县。)
insert into City values(1,'南宁市',28)
insert into City values(2,'柳州市',28)
insert into City values(3,'桂林市',28)
insert into City values(4,'梧州市',28)
insert into City values(5,'北海市',28)
insert into City values(6,'防城港市',28)
insert into City values(7,'钦州市',28)
insert into City values(8,'贵港市',28)
insert into City values(9,'玉林市',28)
insert into City values(10,'百色市',28)
insert into City values(11,'贺州市',28)
insert into City values(12,'河池市',28)
insert into City values(13,'来宾市',28)
insert into City values(14,'崇左市',28)
--select * from City where pid=28 order by cid
----------------------------------------------------------------
--29西藏自治区(2005年辖:1个地级市、6个地区;1个市辖区、1个县级市、71个县。)
insert into City values(1,'拉萨市',29)
insert into City values(2,'那曲地区',29)
insert into City values(3,'昌都地区',29)
insert into City values(4,'山南地区',29)
insert into City values(5,'日喀则地区',29)
insert into City values(6,'阿里地区',29)
insert into City values(7,'林芝地区',29)
--select * from City where pid=29 order by cid
----------------------------------------------------------------
--30宁夏回族自治区
insert into City values(1,'银川市',30)
insert into City values(2,'石嘴山市',30)
insert into City values(3,'吴忠市',30)
insert into City values(4,'固原市',30)
insert into City values(5,'中卫市',30)
--select * from City where pid=30 order by cid
----------------------------------------------------------------
--31新疆维吾尔自治区(2005年辖:2个地级市、7个地区、5个自治州;11个市辖区、20个县级市、62个县、6个自治县)
insert into City values(1,'乌鲁木齐市',31)
insert into City values(2,'克拉玛依市',31)
insert into City values(3,'石河子市 ',31)
insert into City values(4,'阿拉尔市',31)
insert into City values(5,'图木舒克市',31)
insert into City values(6,'五家渠市',31)
insert into City values(7,'吐鲁番市',31)
insert into City values(8,'阿克苏市',31)
insert into City values(9,'喀什市',31)
insert into City values(10,'哈密市',31)
insert into City values(11,'和田市',31)
insert into City values(12,'阿图什市',31)
insert into City values(13,'库尔勒市',31)
insert into City values(14,'昌吉市 ',31)
insert into City values(15,'阜康市',31)
insert into City values(16,'米泉市',31)
insert into City values(17,'博乐市',31)
insert into City values(18,'伊宁市',31)
insert into City values(19,'奎屯市',31)
insert into City values(20,'塔城市',31)
insert into City values(21,'乌苏市',31)
insert into City values(22,'阿勒泰市',31)
--select * from City where pid=31 order by cid
----------------------------------------------------------------
--32内蒙古自治区(2006年,辖:9个地级市、3个盟;21个市辖区、11个县级市、17个县、49个旗、3个自治旗。)
insert into City values(1,'呼和浩特市',32)
insert into City values(2,'包头市',32)
insert into City values(3,'乌海市',32)
insert into City values(4,'赤峰市',32)
insert into City values(5,'通辽市',32)
insert into City values(6,'鄂尔多斯市',32)
insert into City values(7,'呼伦贝尔市',32)
insert into City values(8,'巴彦淖尔市',32)
insert into City values(9,'乌兰察布市',32)
insert into City values(10,'锡林郭勒盟',32)
insert into City values(11,'兴安盟',32)
insert into City values(12,'阿拉善盟',32)
--select * from City where pid=32 order by
----------------------------------------------------------------
--33澳门特别行政区
insert into City values(1,'澳门特别行政区',33)
--select * from City where pid=33 order by cid
----------------------------------------------------------------
--34香港特别行政区
insert into City values(1,'香港特别行政区',34)
--select * from City where pid=34 order by cid
----------------------------------------------------------------
1. 建中转库和表。
这里没什么可说的,我觉得比较有用的一点就是判断数据中是否存在数据库或者表,
--判断数据库是否存在,不存在就创建(默认路径下)然后切换到创建的数据库来
If not exists (select * from master.dbo.sysdababases where name=’数据库名’)
Create database 数据库名
Use 数据库名
--判断表是否存在,存在就删除然后重新创建
--注意这里的uniqueidentifier类型,可产生32位的不重复的字符串,一般用来标识列,--插入的时候用newID()方法
If exists (select * from sysobjects where id=object_id(‘表名’) and type=’u’)
Drop table 表名
Create table Provincial(pid uniqueidentifier , province varchar(50), primary key (pid) )
2.迁移数据的存储过程
这里先要介绍下源数据库的结构,源数据库从最终目的来看主要存放的两个表的数据,但是为了某些目的,实际分成了很多表,其中有一个表,记录了这个实际的表存放的表名,比如说存放了A表和B表,现在我这么存放,把A的数据分成若干表,每个表存放1W条数据,有20张,A1,A2…,A20, 把B的数据分成若干表,每个表存放2W条数据,有10张,B1,B2…,B20,还有另外一张表AB,存放的是存放数据的表名(tb_name)。实际上我的迁移过程是通过分析这张表的结构来之后精心设计的。主要用到游标。
--思路:1,首先从AB中找出所有的同构表名。
--2,使用游标取出一个表名,通过字符串拼接的方法,拼接成一个数据迁移的sql语句,--然后执行sql语句。
--3.游标循环,执行所有表的数据迁移。
Go
Create procedure transferdata
As
Declare mycursor cursor for
Select tb_name from AB where tb_name like ‘%A%’
Open mycusor
Declare @tableStr varchar(100)
Delare @sourceDB varchar(100)
Set @sourceDB=’源数据库名.dbo.’
Delare @targetDB varchar(100)
Set @targetDB =’目标数据库名.dbo.A’
Declare @sql varchar(1000)
Fetch next from mycursor into @tableStr
While(@@fetch_status=0)
Begin
Set @sql=N’insert into ’+@targetDB+’ (id,name,sex,address) select newID(),tname,tsex,taddress from ’+@sourceDB+@tableStr
--执行文本的sql语句
Exec sp_executesql @sql
Fetch next from mycursor into @tableStr
End
Close mycursor
Deallocate mycursor
Exec transferdata
3.去掉无效的,重复的,修正地域字段的过程。
--去掉无效的数据(长度小于三的和含有数字或者字母的)
Delete from A where len(Ltrim(Rtrim(city)))<=3 or patindex(‘[A-Z,a-z,0-9]’,city)>0
--去掉重复的数据,只保留一条ID最小的,根据一个字段name来判断
Delete from A where name in (select name from A group by name having count(name)>1) and id not in (select min(convert(varchar(50),id)) from A group by name having count(name)>1))
--去掉重复的数据,只保留id最大的一条,根据多个字段来判断。
Delete A from A a
Where exists(select * from A where name=a.name and address=a.address and id>a.id)
--修正地域字段,假设地域字段都有值,不过不规范,现在要做的事情就是把它们修正为规--范的省份或者城市,至于找不到的就修正为中国。
If exists (select * from dbo.sysobjects where id=object_id(‘modifyRegion’) and objectproperty(id,N’modifyRegion’)=1)
Drop procedure modifyRegion
Go
Create procedure modifyRegion
As
Declare regioncursor cursor for
Select distinct city from A
Open regioncursor
Declare @regionItem nvarchar(50)
Fetch next from regioncursor into @regionItem
While(@@fetch_status=0)
Begin
--先判断省份是为了处理省市同名的取大的一定对。
If exists(select provincial from Provincial where provincial like ‘%’+@regionItem+’%’ )
Update A set city=( select min(provincial) from Provincial where provincial like ‘%’+@regionItem+’%’) where city=@regionItem
Else if exists (select city from City where city like ‘%’+@regionItem+’%’ )
Update A set city=( select min(city) from City where city like ‘%’+@regionItem+’%’) where city=@regionItem
Else
Update A set city=’中国’ where city=@regionItem
Fetch next from regioncursor into @regionItem
end
close regioncursor
deallocate regioncursor
go
exec modifyRegion
4.分享一个中国城市和省份的有用资料。
这是我无意中找到的,常用的资料,大家可以看看。
--省级 Provincial
--城市 City
create table Provincial(pid int,Provincial varchar(50),primary key (pid))
insert into Provincial values(1,'北京市')
insert into Provincial values(2,'天津市')
insert into Provincial values(3,'上海市')
insert into Provincial values(4,'重庆市')
insert into Provincial values(5,'河北省')
insert into Provincial values(6,'山西省')
insert into Provincial values(7,'台湾省')
insert into Provincial values(8,'辽宁省')
insert into Provincial values(9,'吉林省')
insert into Provincial values(10,'黑龙江省')
insert into Provincial values(11,'江苏省')
insert into Provincial values(12,'浙江省')
insert into Provincial values(13,'安徽省')
insert into Provincial values(14,'福建省')
insert into Provincial values(15,'江西省')
insert into Provincial values(16,'山东省')
insert into Provincial values(17,'河南省')
insert into Provincial values(18,'湖北省')
insert into Provincial values(19,'湖南省')
insert into Provincial values(20,'广东省')
insert into Provincial values(21,'甘肃省')
insert into Provincial values(22,'四川省')
insert into Provincial values(23,'贵州省')
insert into Provincial values(24,'海南省')
insert into Provincial values(25,'云南省')
insert into Provincial values(26,'青海省')
insert into Provincial values(27,'陕西省')
insert into Provincial values(28,'广西壮族自治区')
insert into Provincial values(29,'西藏自治区')
insert into Provincial values(30,'宁夏回族自治区')
insert into Provincial values(31,'新疆维吾尔自治区')
insert into Provincial values(32,'内蒙古自治区')
insert into Provincial values(33,'澳门特别行政区')
insert into Provincial values(34,'香港特别行政区')
--select pid,Provincial from Provincial
create table City(cid int not null,city varchar(50) primary key,pid int foreign key references Provincial(pid))
----------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------
--插入各个省的城市数据
--4个直辖市
insert into City values(1,'北京市',1)
insert into City values(1,'天津市',2)
insert into City values(1,'上海市',3)
insert into City values(1,'重庆市',4)
--select * from City where pid=4
----------------------------------------------------------------
--5河北省 11个地级市
insert into City values(1,'石家庄市',5)
insert into City values(2,'唐山市',5)
insert into City values(3,'秦皇岛市',5)
insert into City values(4,'邯郸市',5)
insert into City values(5,'邢台市',5)
insert into City values(6,'保定市',5)
insert into City values(7,'张家口市',5)
insert into City values(8,'承德市',5)
insert into City values(9,'沧州市',5)
insert into City values(10,'廊坊市',5)
insert into City values(11,'衡水市',5)
--select * from City where pid=5 order by cid
----------------------------------------------------------------
--6山西省 11个城市
insert into City values(1,'太原市',6)
insert into City values(2,'大同市',6)
insert into City values(3,'阳泉市',6)
insert into City values(4,'长治市',6)
insert into City values(5,'晋城市',6)
insert into City values(6,'朔州市',6)
insert into City values(7,'晋中市',6)
insert into City values(8,'运城市',6)
insert into City values(9,'忻州市',6)
insert into City values(10,'临汾市',6)
insert into City values(11,'吕梁市',6)
--select * from City where pid=6 order by cid
----------------------------------------------------------------
--7台湾省(台湾本岛和澎湖共设7市、16县,其中台北市和高雄市为“院辖市”,直属“行政院”,其余属台湾省;市下设区,县下设市(县辖市)、镇、乡,合称区市镇乡。)
insert into City values(1,'台北市',7)
insert into City values(2,'高雄市',7)
insert into City values(3,'基隆市',7)
insert into City values(4,'台中市',7)
insert into City values(5,'台南市',7)
insert into City values(6,'新竹市',7)
insert into City values(7,'嘉义市',7)
insert into City values(8,'台北县',7)
insert into City values(9,'宜兰县',7)
insert into City values(10,'桃园县',7)
insert into City values(11,'新竹县',7)
insert into City values(12,'苗栗县',7)
insert into City values(13,'台中县',7)
insert into City values(14,'彰化县',7)
insert into City values(15,'南投县',7)
insert into City values(16,'云林县',7)
insert into City values(17,'嘉义县',7)
insert into City values(18,'台南县',7)
insert into City values(19,'高雄县',7)
insert into City values(20,'屏东县',7)
insert into City values(21,'澎湖县',7)
insert into City values(22,'台东县',7)
insert into City values(23,'花莲县',7)
--select * from City where pid=7 order by cid
----------------------------------------------------------------
--8辽宁省 14个地级市
insert into City values(1,'沈阳市',8)
insert into City values(2,'大连市',8)
insert into City values(3,'鞍山市',8)
insert into City values(4,'抚顺市',8)
insert into City values(5,'本溪市',8)
insert into City values(6,'丹东市',8)
insert into City values(7,'锦州市',8)
insert into City values(8,'营口市',8)
insert into City values(9,'阜新市',8)
insert into City values(10,'辽阳市',8)
insert into City values(11,'盘锦市',8)
insert into City values(12,'铁岭市',8)
insert into City values(13,'朝阳市',8)
insert into City values(14,'葫芦岛市',8)
--select * from City where pid=8 order by cid
----------------------------------------------------------------
--9吉林省(2006年,辖:8个地级市、1个自治州;20个市辖区、20个县级市、17个县、3个自治县。)
insert into City values(1,'长春市',9)
insert into City values(2,'吉林市',9)
insert into City values(3,'四平市',9)
insert into City values(4,'辽源市',9)
insert into City values(5,'通化市',9)
insert into City values(6,'白山市',9)
insert into City values(7,'松原市',9)
insert into City values(8,'白城市',9)
insert into City values(9,'延边朝鲜族自治州',9)
--select * from City where pid=9 order by cid
----------------------------------------------------------------
--10黑龙江省(2006年,辖:12地级市、1地区;64市辖区、18县级市、45县、1自治县)
insert into City values(1,'哈尔滨市',10)
insert into City values(2,'齐齐哈尔市',10)
insert into City values(3,'鹤 岗 市',10)
insert into City values(4,'双鸭山市',10)
insert into City values(5,'鸡 西 市',10)
insert into City values(6,'大 庆 市',10)
insert into City values(7,'伊 春 市',10)
insert into City values(8,'牡丹江市',10)
insert into City values(9,'佳木斯市',10)
insert into City values(10,'七台河市',10)
insert into City values(11,'黑 河 市',10)
insert into City values(12,'绥 化 市',10)
insert into City values(13,'大兴安岭地区',10)
--select * from City where pid=10 order by cid
----------------------------------------------------------------
--11江苏省(2005年辖:13个地级市;54个市辖区、27个县级市、25个县)
insert into City values(1,'南京市',11)
insert into City values(2,'无锡市',11)
insert into City values(3,'徐州市',11)
insert into City values(4,'常州市',11)
insert into City values(5,'苏州市',11)
insert into City values(6,'南通市',11)
insert into City values(7,'连云港市',11)
insert into City values(8,'淮安市',11)
insert into City values(9,'盐城市',11)
insert into City values(10,'扬州市',11)
insert into City values(11,'镇江市',11)
insert into City values(12,'泰州市',11)
insert into City values(13,'宿迁市',11)
--select * from City where pid=11 order by cid
----------------------------------------------------------------
--12浙江省(2006年,辖:11个地级市;32个市辖区、22个县级市、35个县、1个自治县。)
insert into City values(1,'杭州市',12)
insert into City values(2,'宁波市',12)
insert into City values(3,'温州市',12)
insert into City values(4,'嘉兴市',12)
insert into City values(5,'湖州市',12)
insert into City values(6,'绍兴市',12)
insert into City values(7,'金华市',12)
insert into City values(8,'衢州市',12)
insert into City values(9,'舟山市',12)
insert into City values(10,'台州市',12)
insert into City values(11,'丽水市',12)
--select * from City where pid=12 order by cid
----------------------------------------------------------------
--13安徽省(2005年辖:17个地级市;44个市辖区、5县个级市、56个县。)
insert into City values(1,'合肥市',13)
insert into City values(2,'芜湖市',13)
insert into City values(3,'蚌埠市',13)
insert into City values(4,'淮南市',13)
insert into City values(5,'马鞍山市',13)
insert into City values(6,'淮北市',13)
insert into City values(7,'铜陵市',13)
insert into City values(8,'安庆市',13)
insert into City values(9,'黄山市',13)
insert into City values(10,'滁州市',13)
insert into City values(11,'阜阳市',13)
insert into City values(12,'宿州市',13)
insert into City values(13,'巢湖市',13)
insert into City values(14,'六安市',13)
insert into City values(15,'亳州市',13)
insert into City values(16,'池州市',13)
insert into City values(17,'宣城市',13)
--select * from City where pid=13 order by cid
----------------------------------------------------------------
--14福建省(2006年辖:9个地级市;26个市辖区、14个县级市、45个县。)
insert into City values(1,'福州市',14)
insert into City values(2,'厦门市',14)
insert into City values(3,'莆田市',14)
insert into City values(4,'三明市',14)
insert into City values(5,'泉州市',14)
insert into City values(6,'漳州市',14)
insert into City values(7,'南平市',14)
insert into City values(8,'龙岩市',14)
insert into City values(9,'宁德市',14)
--select * from City where pid=14 order by cid
----------------------------------------------------------------
--15江西省(2006年全省辖:11个地级市;19个市辖区、10个县级市、70个县。)
insert into City values(1,'南昌市',15)
insert into City values(2,'景德镇市',15)
insert into City values(3,'萍乡市',15)
insert into City values(4,'九江市',15)
insert into City values(5,'新余市',15)
insert into City values(6,'鹰潭市',15)
insert into City values(7,'赣州市',15)
insert into City values(8,'吉安市',15)
insert into City values(9,'宜春市',15)
insert into City values(10,'抚州市',15)
insert into City values(11,'上饶市',15)
--select * from City where pid=15 order by cid
----------------------------------------------------------------
--16山东省(2005年,辖:17个地级市;49个市辖区、31个县级市、60个县。)
insert into City values(1,'济南市',16)
insert into City values(2,'青岛市',16)
insert into City values(3,'淄博市',16)
insert into City values(4,'枣庄市',16)
insert into City values(5,'东营市',16)
insert into City values(6,'烟台市',16)
insert into City values(7,'潍坊市',16)
insert into City values(8,'济宁市',16)
insert into City values(9,'泰安市',16)
insert into City values(10,'威海市',16)
insert into City values(11,'日照市',16)
insert into City values(12,'莱芜市',16)
insert into City values(13,'临沂市',16)
insert into City values(14,'德州市',16)
insert into City values(15,'聊城市',16)
insert into City values(16,'滨州市',16)
insert into City values(17,'菏泽市',16)
--select * from City where pid=16 order by cid
----------------------------------------------------------------
--17河南省 17个地级市
insert into City values(1,'郑州市',17)
insert into City values(2,'开封市',17)
insert into City values(3,'洛阳市',17)
insert into City values(4,'平顶山市',17)
insert into City values(5,'安阳市',17)
insert into City values(6,'鹤壁市',17)
insert into City values(7,'新乡市',17)
insert into City values(8,'焦作市',17)
insert into City values(9,'濮阳市',17)
insert into City values(10,'许昌市',17)
insert into City values(11,'漯河市',17)
insert into City values(12,'三门峡市',17)
insert into City values(13,'南阳市',17)
insert into City values(14,'商丘市',17)
insert into City values(15,'信阳市',17)
insert into City values(16,'周口市',17)
insert into City values(17,'驻马店市',17)
insert into City values(18,'济源市',17)
--select * from City where pid=17 order by cid
----------------------------------------------------------------
--18湖北省(截至2005年12月31日,全省辖13个地级单位(12个地级市、1个自治州);102县级单位(38个市辖区、24个县级市、37个县、2个自治县、1个林区),共有1220个乡级单位(277个街道、733个镇、210个乡)。)
insert into City values(1,'武汉市',18)
insert into City values(2,'黄石市',18)
insert into City values(3,'十堰市',18)
insert into City values(4,'荆州市',18)
insert into City values(5,'宜昌市',18)
insert into City values(6,'襄樊市',18)
insert into City values(7,'鄂州市',18)
insert into City values(8,'荆门市',18)
insert into City values(9,'孝感市',18)
insert into City values(10,'黄冈市',18)
insert into City values(11,'咸宁市',18)
insert into City values(12,'随州市',18)
insert into City values(13,'仙桃市',18)
insert into City values(14,'天门市',18)
insert into City values(15,'潜江市',18)
insert into City values(16,'神农架林区',18)
insert into City values(17,'恩施土家族苗族自治州',18)
--select * from City where pid=18 order by cid
----------------------------------------------------------------
--19湖南省(2005年辖:13个地级市、1个自治州;34个市辖区、16个县级市、65个县、7个自治县。)
insert into City values(1,'长沙市',19)
insert into City values(2,'株洲市',19)
insert into City values(3,'湘潭市',19)
insert into City values(4,'衡阳市',19)
insert into City values(5,'邵阳市',19)
insert into City values(6,'岳阳市',19)
insert into City values(7,'常德市',19)
insert into City values(8,'张家界市',19)
insert into City values(9,'益阳市',19)
insert into City values(10,'郴州市',19)
insert into City values(11,'永州市',19)
insert into City values(12,'怀化市',19)
insert into City values(13,'娄底市',19)
insert into City values(14,'湘西土家族苗族自治州',19)
--select * from City where pid=19 order by cid
----------------------------------------------------------------
--20广东省(截至2005年12月31日,广东省辖:21个地级市,54个市辖区、23个县级市、41个县、3个自治县,429个街道办事处、1145个镇、4个乡、7个民族乡。)
insert into City values(1,'广州市',20)
insert into City values(2,'深圳市',20)
insert into City values(3,'珠海市',20)
insert into City values(4,'汕头市',20)
insert into City values(5,'韶关市',20)
insert into City values(6,'佛山市',20)
insert into City values(7,'江门市',20)
insert into City values(8,'湛江市',20)
insert into City values(9,'茂名市',20)
insert into City values(10,'肇庆市',20)
insert into City values(11,'惠州市',20)
insert into City values(12,'梅州市',20)
insert into City values(13,'汕尾市',20)
insert into City values(14,'河源市',20)
insert into City values(15,'阳江市',20)
insert into City values(16,'清远市',20)
insert into City values(17,'东莞市',20)
insert into City values(18,'中山市',20)
insert into City values(19,'潮州市',20)
insert into City values(20,'揭阳市',20)
insert into City values(21,'云浮市',20)
--select * from City where pid=20 order by cid
----------------------------------------------------------------
--21甘肃省 12个地级市、2个自治州
insert into City values(1,'兰州市',21)
insert into City values(2,'金昌市',21)
insert into City values(3,'白银市',21)
insert into City values(4,'天水市',21)
insert into City values(5,'嘉峪关市',21)
insert into City values(6,'武威市',21)
insert into City values(7,'张掖市',21)
insert into City values(8,'平凉市',21)
insert into City values(9,'酒泉市',21)
insert into City values(10,'庆阳市',21)
insert into City values(11,'定西市',21)
insert into City values(12,'陇南市',21)
insert into City values(13,'临夏回族自治州',21)
insert into City values(14,'甘南藏族自治州',21)
--select * from City where pid=21 order by cid
----------------------------------------------------------------
--22四川省18个地级市、3个自治州
insert into City values(1,'成都市',22)
insert into City values(2,'自贡市',22)
insert into City values(3,'攀枝花市',22)
insert into City values(4,'泸州市',22)
insert into City values(5,'德阳市',22)
insert into City values(6,'绵阳市',22)
insert into City values(7,'广元市',22)
insert into City values(8,'遂宁市',22)
insert into City values(9,'内江市',22)
insert into City values(10,'乐山市',22)
insert into City values(11,'南充市',22)
insert into City values(12,'眉山市',22)
insert into City values(13,'宜宾市',22)
insert into City values(14,'广安市',22)
insert into City values(15,'达州市',22)
insert into City values(16,'雅安市',22)
insert into City values(17,'巴中市',22)
insert into City values(18,'资阳市',22)
insert into City values(19,'阿坝藏族羌族自治州',22)
insert into City values(20,'甘孜藏族自治州',22)
insert into City values(21,'凉山彝族自治州',22)
--select * from City where pid=22 order by cid
----------------------------------------------------------------
--23贵州省(2006年辖:4个地级市、2个地区、3个自治州;10个市辖区、9个县级市、56个县、11个自治县、2个特区。)
insert into City values(1,'贵阳市',23)
insert into City values(2,'六盘水市',23)
insert into City values(3,'遵义市',23)
insert into City values(4,'安顺市',23)
insert into City values(5,'铜仁地区',23)
insert into City values(6,'毕节地区',23)
insert into City values(7,'黔西南布依族苗族自治州',23)
insert into City values(8,'黔东南苗族侗族自治州',23)
insert into City values(9,'黔南布依族苗族自治州',23)
--select * from City where pid=23 order by cid
----------------------------------------------------------------
--24海南省全省有2个地级市,6个县级市,4个县,6个民族自治县,4个市辖区,1个办事处(西南中沙群岛办事处 ,县级)。)
insert into City values(1,'海口市',24)
insert into City values(2,'三亚市',24)
insert into City values(3,'五指山市',24)
insert into City values(4,'琼海市',24)
insert into City values(5,'儋州市',24)
insert into City values(6,'文昌市',24)
insert into City values(7,'万宁市',24)
insert into City values(8,'东方市',24)
insert into City values(9,'澄迈县',24)
insert into City values(10,'定安县',24)
insert into City values(11,'屯昌县',24)
insert into City values(12,'临高县',24)
insert into City values(13,'白沙黎族自治县',24)
insert into City values(14,'昌江黎族自治县',24)
insert into City values(15,'乐东黎族自治县',24)
insert into City values(16,'陵水黎族自治县',24)
insert into City values(17,'保亭黎族苗族自治县',24)
insert into City values(18,'琼中黎族苗族自治县',24)
--select * from City where pid=24 order by cid
----------------------------------------------------------------
--25云南省(2006年辖:8个地级市、8个自治州;12个市辖区、9个县级市、79个县、29个自治县。)
insert into City values(1,'昆明市',25)
insert into City values(2,'曲靖市',25)
insert into City values(3,'玉溪市',25)
insert into City values(4,'保山市',25)
insert into City values(5,'昭通市',25)
insert into City values(6,'丽江市',25)
insert into City values(7,'思茅市',25)
insert into City values(8,'临沧市',25)
insert into City values(9,'文山壮族苗族自治州',25)
insert into City values(10,'红河哈尼族彝族自治州',25)
insert into City values(11,'西双版纳傣族自治州',25)
insert into City values(12,'楚雄彝族自治州',25)
insert into City values(13,'大理白族自治州',25)
insert into City values(14,'德宏傣族景颇族自治州',25)
insert into City values(15,'怒江傈傈族自治州',25)
insert into City values(16,'迪庆藏族自治州',25)
--select * from City where pid=25 order by cid
----------------------------------------------------------------
--26青海省(2006年辖:1个地级市、1个地区、6个自治州;4个市辖区、2个县级市、30个县、7个自治县。)
insert into City values(1,'西宁市',26)
insert into City values(2,'海东地区',26)
insert into City values(3,'海北藏族自治州',26)
insert into City values(4,'黄南藏族自治州',26)
insert into City values(5,'海南藏族自治州',26)
insert into City values(6,'果洛藏族自治州',26)
insert into City values(7,'玉树藏族自治州',26)
insert into City values(8,'海西蒙古族藏族自治州',26)
--select * from City where pid=26 order by cid
----------------------------------------------------------------
--27陕西省(2006年辖:10个地级市;24个市辖区、3个县级市、80个县。)
insert into City values(1,'西安市',27)
insert into City values(2,'铜川市',27)
insert into City values(3,'宝鸡市',27)
insert into City values(4,'咸阳市',27)
insert into City values(5,'渭南市',27)
insert into City values(6,'延安市',27)
insert into City values(7,'汉中市',27)
insert into City values(8,'榆林市',27)
insert into City values(9,'安康市',27)
insert into City values(10,'商洛市',27)
--select * from City where pid=27 order by cid
----------------------------------------------------------------
--28广西壮族自治区(2005年辖:14个地级市;34个市辖区、7个县级市、56个县、12个自治县。)
insert into City values(1,'南宁市',28)
insert into City values(2,'柳州市',28)
insert into City values(3,'桂林市',28)
insert into City values(4,'梧州市',28)
insert into City values(5,'北海市',28)
insert into City values(6,'防城港市',28)
insert into City values(7,'钦州市',28)
insert into City values(8,'贵港市',28)
insert into City values(9,'玉林市',28)
insert into City values(10,'百色市',28)
insert into City values(11,'贺州市',28)
insert into City values(12,'河池市',28)
insert into City values(13,'来宾市',28)
insert into City values(14,'崇左市',28)
--select * from City where pid=28 order by cid
----------------------------------------------------------------
--29西藏自治区(2005年辖:1个地级市、6个地区;1个市辖区、1个县级市、71个县。)
insert into City values(1,'拉萨市',29)
insert into City values(2,'那曲地区',29)
insert into City values(3,'昌都地区',29)
insert into City values(4,'山南地区',29)
insert into City values(5,'日喀则地区',29)
insert into City values(6,'阿里地区',29)
insert into City values(7,'林芝地区',29)
--select * from City where pid=29 order by cid
----------------------------------------------------------------
--30宁夏回族自治区
insert into City values(1,'银川市',30)
insert into City values(2,'石嘴山市',30)
insert into City values(3,'吴忠市',30)
insert into City values(4,'固原市',30)
insert into City values(5,'中卫市',30)
--select * from City where pid=30 order by cid
----------------------------------------------------------------
--31新疆维吾尔自治区(2005年辖:2个地级市、7个地区、5个自治州;11个市辖区、20个县级市、62个县、6个自治县)
insert into City values(1,'乌鲁木齐市',31)
insert into City values(2,'克拉玛依市',31)
insert into City values(3,'石河子市 ',31)
insert into City values(4,'阿拉尔市',31)
insert into City values(5,'图木舒克市',31)
insert into City values(6,'五家渠市',31)
insert into City values(7,'吐鲁番市',31)
insert into City values(8,'阿克苏市',31)
insert into City values(9,'喀什市',31)
insert into City values(10,'哈密市',31)
insert into City values(11,'和田市',31)
insert into City values(12,'阿图什市',31)
insert into City values(13,'库尔勒市',31)
insert into City values(14,'昌吉市 ',31)
insert into City values(15,'阜康市',31)
insert into City values(16,'米泉市',31)
insert into City values(17,'博乐市',31)
insert into City values(18,'伊宁市',31)
insert into City values(19,'奎屯市',31)
insert into City values(20,'塔城市',31)
insert into City values(21,'乌苏市',31)
insert into City values(22,'阿勒泰市',31)
--select * from City where pid=31 order by cid
----------------------------------------------------------------
--32内蒙古自治区(2006年,辖:9个地级市、3个盟;21个市辖区、11个县级市、17个县、49个旗、3个自治旗。)
insert into City values(1,'呼和浩特市',32)
insert into City values(2,'包头市',32)
insert into City values(3,'乌海市',32)
insert into City values(4,'赤峰市',32)
insert into City values(5,'通辽市',32)
insert into City values(6,'鄂尔多斯市',32)
insert into City values(7,'呼伦贝尔市',32)
insert into City values(8,'巴彦淖尔市',32)
insert into City values(9,'乌兰察布市',32)
insert into City values(10,'锡林郭勒盟',32)
insert into City values(11,'兴安盟',32)
insert into City values(12,'阿拉善盟',32)
--select * from City where pid=32 order by
----------------------------------------------------------------
--33澳门特别行政区
insert into City values(1,'澳门特别行政区',33)
--select * from City where pid=33 order by cid
----------------------------------------------------------------
--34香港特别行政区
insert into City values(1,'香港特别行政区',34)
--select * from City where pid=34 order by cid
----------------------------------------------------------------
相关推荐
### 从Evernote将数据迁移到印象笔记的图文步骤 #### 背景与需求 随着印象笔记(中文版)的推出,许多原本使用其国际版Evernote的用户希望能够将原有的数据迁移到印象笔记中。这不仅涉及到简单的数据转移,还涉及...
MyBatis学习总结笔记 MyBatis是一个优秀的持久层框架,它支持自定义SQL、存储过程以及高级映射。MyBatis免除了几乎所有的JDBC代码以及设置参数和获取结果集的工作。MyBatis可以通过简单的XML或注解来配置和映射原始...
Oracle Data Pump 是一种高效的数据迁移工具,它能够显著提升数据导入导出的速度。Data Pump 的主要优点包括简化了用户界面、提供了多种导出导入模式以及支持并行处理等特性。下面将详细介绍 Oracle Data Pump 的...
数据集成负责不同数据源之间的数据迁移。机器学习PAI是构建在MaxCompute上的机器学习平台,用户可以在不迁移数据的情况下进行模型训练和预测。AnalyticDB是一款实时分析服务,与MaxCompute配合,实现从离线到在线的...
这种知识迁移的能力使得模型在面对小数据集或新任务时能够更快地收敛,提高模型的泛化能力。 **与域自适应的关系** 域自适应(Domain Adaptation)是迁移学习的一种特例,主要处理源任务和目标任务之间数据分布不...
总结来说,Oracle数据库的启动和关闭涉及到多个步骤和模式,理解并熟练掌握这些操作对于数据库的稳定运行和高效维护至关重要。对于初学者,通过实践和学习这些基本操作,可以逐步深入到更复杂的数据库管理和优化任务...
以上只是Oracle笔记总结的一部分,Oracle数据库系统的深度和广度远不止于此,包括数据库设计、PL/SQL编程、数据库复制、数据迁移等都是Oracle学习的重要领域。通过深入学习和实践,你可以更好地理解和驾驭这个强大的...
它由阿里巴巴集团开发并开源,广泛应用于大数据处理场景下的数据迁移、ETL等任务。 #### 二、DataX部署步骤详解 **1. 下载DataX** - **下载地址**:从提供的链接()下载DataX最新版本的压缩包。 - **注意事项**...
5. **数据迁移和转换**:确保数据从源系统到数据仓库的成功迁移。 6. **选择合适的硬件**:根据数据量和访问模式选择合适的硬件配置。 7. **选择合适的软件**:根据需求选择合适的数据库软件。 8. **选择合适的数据...
DM 是 TiDB 的数据迁移工具,专门设计用于将 MySQL、MariaDB 或 Aurora MySQL 数据库中的数据迁移到 TiDB。DM 工具简化了迁移过程,降低了运维成本,支持全量数据迁移和增量数据同步,确保了从源数据库到 TiDB 的...
2. **备份数据**:迁移前请备份重要数据,以防万一迁移过程中出现问题导致数据丢失。 3. **下载分区助手软件**:分区助手是一款强大的磁盘管理工具,可以帮助您轻松地将系统迁移至固态硬盘。您可以从官方网站或可信...
总结,CRM软件的实施是一项复杂且重要的任务,涉及到需求分析、选型、系统设计、数据迁移等多个环节。源码的利用和各种工具的应用是实施过程中的关键因素,它们可以帮助企业实现高效、定制化的CRM系统,提升业务运作...
MyBatis 最初是从 Apache Software Foundation 迁移到 Google Code 的 iBatis 项目,后来在 2013 年再次迁移至 Github。 要获取 Mybatis,可以通过 Maven 仓库或直接访问其 Github 页面。在 Maven 项目中,可以添加...
### Talend学习笔记2——mysql文件导入到HDFS #### 关键知识点概览 - **Talend Data ...通过遵循这些步骤,可以有效地实现数据从传统关系型数据库向 Hadoop 生态系统的迁移,为后续的大数据分析处理打下基础。
迁移学习存在的问题包括数据迁移、模型迁移和个性化需求问题等。这些问题需要通过迁移学习的方法来解决,以满足特定领域应用的需求。 Batch Normalization和迁移学习都是神经网络和机器学习中非常重要的概念,它们...
- **文件存储**: 数据库存储为单个磁盘文件,易于备份和迁移。 2. SQLite数据类型: - NULL:表示空值。 - INTEGER:整数,可自动转换为BIGINT、INTEGER、SMALLINT或TINYINT。 - REAL:浮点数,等同于DOUBLE ...
通过对上述信息的总结与分析,我们可以看出Hive作为Hadoop生态中的重要一环,在大数据处理领域具有不可替代的地位。无论是对于希望从事大数据领域的技术人员,还是对于正在寻找更高效数据处理方案的企业而言,深入...
迁移学习是利用预训练模型在大规模数据集上学习到的知识来解决新任务的一种方法。由于获取大量标记数据和训练大型模型可能成本高昂,迁移学习提供了捷径。预训练模型通常在类似的任务或更大的数据集上训练,然后在...