创建公共配置表,并以全国区县代码维护为例

Posted 我思故我在我有我精彩--liangqihui

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了创建公共配置表,并以全国区县代码维护为例相关的知识,希望对你有一定的参考价值。

---------------------

--创建通用选项表

/****** Object: Table [dbo].[sysComOption] Script Date: 01/08/2017 14:08:18 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[sysComOption](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Code] [nvarchar](20) NOT NULL,
[ParentCode] [nvarchar](20) NULL,
[Version] [int] NOT NULL,
[Status] [int] NOT NULL,
[OptionType] [nvarchar](20) NULL,
[OptionTag] [nvarchar](150) NULL,
[OtherTag] [xml] NULL,
[OptionName] [nvarchar](50) NOT NULL,
[OptionCNName] [nvarchar](50) NOT NULL,
[OptionDisplayName] [nvarchar](50) NULL,
[OptionAbbPYName] [nvarchar](20) NULL,
[OptionFullPYName] [nvarchar](150) NULL,
[OptionValueType] [int] NOT NULL,
[OptionDisplayValue] [nvarchar](50) NULL,
[OptionValueInt] [int] NULL,
[OptionValueNvarchar] [nvarchar](150) NULL,
[OptionValueFloat] [float] NULL,
[OptionValueNum] [numeric](18, 0) NULL,
[Comments] [nvarchar](500) NULL,
[Create_By] [int] NULL,
[Create_date] [datetime] NULL,
[lastmaintenance_by] [int] NULL,
[Lastmodify_date] [datetime] NULL,
CONSTRAINT [PK_sysComOption] PRIMARY KEY CLUSTERED 
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

EXEC sys.sp_addextendedproperty @name=N\'MS_Description\', @value=N\'1 int;5 nvarchat; 10 float;15 Num\' , @level0type=N\'SCHEMA\',@level0name=N\'dbo\', @level1type=N\'TABLE\',@level1name=N\'sysComOption\', @level2type=N\'COLUMN\',@level2name=N\'OptionValueType\'
GO
View Code

 

 

 --创建区县初始化数据表

--创建区县数据初始化表

/****** Object:  Table [dbo].[regionTemp]    Script Date: 01/08/2017 14:09:42 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[regionTemp](
    [code] [float] NULL,
    [parentcode] [varchar](10) NULL,
    [parentRegionname] [nvarchar](255) NULL,
    [Regionname] [nvarchar](255) NULL,
    [GPS] [varchar](46) NULL
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO
View Code

 

code parentcode parentRegionname Regionname GPS
110000 110000 北京市 北京市 GPS(39.9081726,116.3979471)
110101 110000 北京市 东城区 GPS(39.9351199,116.4093947)
110102 110000 北京市 西城区 GPS(39.9351775,116.3638616)
110103 110000 北京市 崇文区 GPS(39.8882042,116.4318180)
110104 110000 北京市 宣武区 GPS(39.8771968,116.3530469)
110105 110000 北京市 朝阳区 GPS(39.9527472,116.4977252)
110106 110000 北京市 丰台区 GPS(39.8307687,116.2682462)

-----------------------------------------------

创建拼音缩写(全拼转换 & 将汉字转换首个拼音大写字母)

/****** Object:  UserDefinedFunction [dbo].[fn_GetFullPinyin]    Script Date: 01/08/2017 14:27:01 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE function [dbo].[fn_GetFullPinyin](@words nVARCHAR(2000),@withblank int)   
--@withblank确定每个中文字转为拼音后,每个汉字之间是否需要留下空格0为不留,1为留
RETURNS VARCHAR(8000)   
AS   

BEGIN 
    DECLARE @word nchar(1) 
    DECLARE @paceword nvarchar(1)
    DECLARE @pinyin VARCHAR(8000) 
    DECLARE @i INT
    DECLARE @words_len INT
    DECLARE @unicode INT
    SET @i = 1 
    SET @words =ltrim(rtrim(@words)) 
    SET @words_len =len(@words) 
    WHILE(@i <= @words_len)--循环取字符
    BEGIN 
    SET @word =substring(@words, @i, 1) 
    SET @unicode =unicode(@word) 
    
    if (@withblank=0)
        begin
            set @paceword =\'\' 
        end
    else if(@withblank=1)
        begin
            set @paceword =SPACE(1) 
        end
    
    SET @pinyin =ISNULL(@pinyin +@paceword ,\'\')+ (CASE WHEN unicode(@word)between 19968 and 19968+20901 then  
    (SELECT TOP  1 py FROM ( 
    SELECT\'a\'AS py,N\'\'AS word 
    UNION ALL SELECT \'ai\',N\'\'
    UNION ALL SELECT\'an\',N\'\'
    UNION ALL SELECT\'ang\',N\'\'
    UNION ALL SELECT\'ao\',N\'\'
    UNION ALL SELECT\'ba\',N\'\'
    UNION ALL SELECT\'bai\',N\'\'--韛兡瓸
    UNION ALL SELECT\'ban\',N\'\'
    UNION ALL SELECT\'bang\',N\'\'
    UNION ALL SELECT\'bao\',N\'\'
    UNION ALL SELECT\'bei\',N\'\'
    UNION ALL SELECT\'ben\',N\'\'
    UNION ALL SELECT\'beng\',N\'\'
    UNION ALL SELECT\'bi\',N\'\'
    UNION ALL SELECT\'bian\',N\'\'
    UNION ALL SELECT\'biao\',N\'\'
    UNION ALL SELECT\'bie\',N\'\'
    UNION ALL SELECT\'bin\',N\'\'
    UNION ALL SELECT\'bing\',N\'\'
    UNION ALL SELECT\'bo\',N\'\'
    UNION ALL SELECT\'bu\',N\'簿\'
    UNION ALL SELECT\'ca\',N\'\'
    UNION ALL SELECT\'cai\',N\'\'--縩乲
    UNION ALL SELECT\'can\',N\'\'
    UNION ALL SELECT\'cang\',N\'\'
    UNION ALL SELECT\'cao\',N\'\'
    UNION ALL SELECT\'ce\',N\'\'
    UNION ALL SELECT\'cen\',N\'\'
    UNION ALL SELECT\'ceng\',N\'\'--硛硳岾猠乽
    UNION ALL SELECT\'cha\',N\'\'
    UNION ALL SELECT\'chai\',N\'\'
    UNION ALL SELECT\'chan\',N\'\'
    UNION ALL SELECT\'chang\',N\'\'
    UNION ALL SELECT\'chao\',N\'\'
    UNION ALL SELECT\'che\',N\'\'
    UNION ALL SELECT\'chen\',N\'\'
    UNION ALL SELECT\'cheng\',N\'\'
    UNION ALL SELECT\'chi\',N\'\'
    UNION ALL SELECT\'chong\',N\'\'
    UNION ALL SELECT\'chou\',N\'\'
    UNION ALL SELECT\'chu\',N\'\'
    UNION ALL SELECT\'chuai\',N\'\'
    UNION ALL SELECT\'chuan\',N\'\'
    UNION ALL SELECT\'chuang\',N\'\'
    UNION ALL SELECT\'chui\',N\'\'
    UNION ALL SELECT\'chun\',N\'\'
    UNION ALL SELECT\'chuo\',N\'\'
    UNION ALL SELECT\'ci\',N\'\'--賜嗭
    UNION ALL SELECT\'cong\',N\'\'
    UNION ALL SELECT\'cou\',N\'\'
    UNION ALL SELECT\'cu\',N\'\'
    UNION ALL SELECT\'cuan\',N\'\'
    UNION ALL SELECT\'cui\',N\'\'
    UNION ALL SELECT\'cun\',N\'籿\'
    UNION ALL SELECT\'cuo\',N\'\'
    UNION ALL SELECT\'da\',N\'\'
    UNION ALL SELECT\'dai\',N\'\'
    UNION ALL SELECT\'dan\',N\'\'
    UNION ALL SELECT\'dang\',N\'\'
    UNION ALL SELECT\'dao\',N\'\'
    UNION ALL SELECT\'de\',N\'\'
    UNION ALL SELECT\'den\',N\'\'
    UNION ALL SELECT\'deng\',N\'\'
    UNION ALL SELECT\'di\',N\'\'
    UNION ALL SELECT\'dia\',N\'\'
    UNION ALL SELECT\'dian\',N\'\'
    UNION ALL SELECT\'diao\',N\'\'
    UNION ALL SELECT\'die\',N\'\'--眰嚸
    UNION ALL SELECT\'ding\',N\'\'
    UNION ALL SELECT\'diu\',N\'\'
    UNION ALL SELECT\'dong\',N\'\'
    UNION ALL SELECT\'dou\',N\'\'
    UNION ALL SELECT\'du\',N\'\'
    UNION ALL SELECT\'duan以上是关于创建公共配置表,并以全国区县代码维护为例的主要内容,如果未能解决你的问题,请参考以下文章

全国城市地级市区县sql

从统计局抓取最新的全国区县数据!!

Mycat探索之旅----常用的分片规则

最新的全国行政区划图在哪里可以下载?

GIS相关网站下载全国的GeoJSON格式数据可以到区县级数据

全国官方最新省市区街道详细邮编物流选用