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

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

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

--创建通用选项表

技术分享
/****** Object: Table [dbo].[sysComOption] Script Date: 01/08/2017 14:08:18 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOCREATE 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]GOEXEC sys.sp_addextendedproperty @name=NMS_Description, @value=N1 int;5 nvarchat; 10 float;15 Num , @level0type=NSCHEMA,@level0name=Ndbo, @level1type=NTABLE,@level1name=NsysComOption, @level2type=NCOLUMN,@level2name=NOptionValueTypeGO
View Code

 

 

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

技术分享
--创建区县数据初始化表/****** Object:  Table [dbo].[regionTemp]    Script Date: 01/08/2017 14:09:42 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOSET ANSI_PADDING ONGOCREATE TABLE [dbo].[regionTemp](    [code] [float] NULL,    [parentcode] [varchar](10) NULL,    [parentRegionname] [nvarchar](255) NULL,    [Regionname] [nvarchar](255) NULL,    [GPS] [varchar](46) NULL) ON [PRIMARY]GOSET ANSI_PADDING OFFGO
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 ONGOSET QUOTED_IDENTIFIER ONGOCREATE 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 (     SELECTaAS py,NAS word     UNION ALL SELECT ai,N    UNION ALL SELECTan,N    UNION ALL SELECTang,N    UNION ALL SELECTao,N    UNION ALL SELECTba,N    UNION ALL SELECTbai,N--韛兡瓸    UNION ALL SELECTban,N    UNION ALL SELECTbang,N    UNION ALL SELECTbao,N    UNION ALL SELECTbei,N    UNION ALL SELECTben,N    UNION ALL SELECTbeng,N    UNION ALL SELECTbi,N    UNION ALL SELECTbian,N    UNION ALL SELECTbiao,N    UNION ALL SELECTbie,N    UNION ALL SELECTbin,N    UNION ALL SELECTbing,N    UNION ALL SELECTbo,N    UNION ALL SELECTbu,N簿    UNION ALL SELECTca,N    UNION ALL SELECTcai,N--縩乲    UNION ALL SELECTcan,N    UNION ALL SELECTcang,N    UNION ALL SELECTcao,N    UNION ALL SELECTce,N    UNION ALL SELECTcen,N    UNION ALL SELECTceng,N--硛硳岾猠乽    UNION ALL SELECTcha,N    UNION ALL SELECTchai,N    UNION ALL SELECTchan,N    UNION ALL SELECTchang,N    UNION ALL SELECTchao,N    UNION ALL SELECTche,N    UNION ALL SELECTchen,N    UNION ALL SELECTcheng,N    UNION ALL SELECTchi,N    UNION ALL SELECTchong,N    UNION ALL SELECTchou,N    UNION ALL SELECTchu,N    UNION ALL SELECTchuai,N    UNION ALL SELECTchuan,N    UNION ALL SELECTchuang,N    UNION ALL SELECTchui,N    UNION ALL SELECTchun,N    UNION ALL SELECTchuo,N    UNION ALL SELECTci,N--賜嗭    UNION ALL SELECTcong,N    UNION ALL SELECTcou,N    UNION ALL SELECTcu,N    UNION ALL SELECTcuan,N    UNION ALL SELECTcui,N    UNION ALL SELECTcun,N籿    UNION ALL SELECTcuo,N    UNION ALL SELECTda,N    UNION ALL SELECTdai,N    UNION ALL SELECTdan,N    UNION ALL SELECTdang,N    UNION ALL SELECTdao,N    UNION ALL SELECTde,N    UNION ALL SELECTden,N    UNION ALL SELECTdeng,N    UNION ALL SELECTdi,N    UNION ALL SELECTdia,N    UNION ALL SELECTdian,N    UNION ALL SELECTdiao,N    UNION ALL SELECTdie,N--眰嚸    UNION ALL SELECTding,N    UNION ALL SELECTdiu,N    UNION ALL SELECTdong,N    UNION ALL SELECTdou,N    UNION ALL SELECTdu,N    UNION ALL SELECTduan,N--籪叾    UNION ALL SELECTdui,N    UNION ALL SELECTdun,N    UNION ALL SELECTduo,N    UNION ALL SELECTe,N    UNION ALL SELECTen,N    UNION ALL SELECTeng,N    UNION ALL SELECTer,N    UNION ALL SELECTfa,N    UNION ALL SELECTfan,N    UNION ALL SELECTfang,N    UNION ALL SELECTfei,N    UNION ALL SELECTfen,N    UNION ALL SELECTfeng,N    UNION ALL SELECTfo,N    UNION ALL SELECTfou,N    UNION ALL SELECTfu,N--鰒猤    UNION ALL SELECTga,N    UNION ALL SELECTgai,N    UNION ALL SELECTgan,N    UNION ALL SELECTgang,N    UNION ALL SELECTgao,N    UNION ALL SELECTge,N    UNION ALL SELECTgei,N    UNION ALL SELECTgen,N    UNION ALL SELECTgeng,N--亙堩啹喼嗰    UNION ALL SELECTgong,N--熕贑兝兣    UNION ALL SELECTgou,N    UNION ALL SELECTgu,N    UNION ALL SELECTgua,N詿    UNION ALL SELECTguai,N    UNION ALL SELECTguan,N    UNION ALL SELECTguang,N    UNION ALL SELECTgui,N    UNION ALL SELECTgun,N    UNION ALL SELECTguo,N    UNION ALL SELECTha,N    UNION ALL SELECThai,N    UNION ALL SELECThan,N    UNION ALL SELECThang,N    UNION ALL SELECThao,N    UNION ALL SELECThe,N    UNION ALL SELECThei,N    UNION ALL SELECThen,N    UNION ALL SELECTheng,N--堼囍    UNION ALL SELECThong,N    UNION ALL SELECThou,N    UNION ALL SELECThu,N    UNION ALL SELECThua,N    UNION ALL SELECThuai,N    UNION ALL SELECThuan,N    UNION ALL SELECThuang,N    UNION ALL SELECThui,N    UNION ALL SELECThun,N    UNION ALL SELECThuo,N    UNION ALL SELECTji,N    UNION ALL SELECTjia,N    UNION ALL SELECTjian,N    UNION ALL SELECTjiang,N    UNION ALL SELECTjiao,N    UNION ALL SELECTjie,N    UNION ALL SELECTjin,N    UNION ALL SELECTjing,N    UNION ALL SELECTjiong,N    UNION ALL SELECTjiu,N    UNION ALL SELECTju,N    UNION ALL SELECTjuan,N    UNION ALL SELECTjue,N    UNION ALL SELECTjun,N    UNION ALL SELECTka,N    UNION ALL SELECTkai,N--鎎乫    UNION ALL SELECTkan,N    UNION ALL SELECTkang,N    UNION ALL SELECTkao,N    UNION ALL SELECTke,N    UNION ALL SELECTken,N    UNION ALL SELECTkeng,N--巪乬唟厼怾    UNION ALL SELECTkong,N    UNION ALL SELECTkou,N    UNION ALL SELECTku,N    UNION ALL SELECTkua,N    UNION ALL SELECTkuai,N    UNION ALL SELECTkuan,N    UNION ALL SELECTkuang,N    UNION ALL SELECTkui,N    UNION ALL SELECTkun,N    UNION ALL SELECTkuo,N    UNION ALL SELECTla,N    UNION ALL SELECTlai,N    UNION ALL SELECTlan,N    UNION ALL SELECTlang,N    UNION ALL SELECTlao,N    UNION ALL SELECTle,N    UNION ALL SELECTlei,N--嘞脷    UNION ALL SELECTleng,N    UNION ALL SELECTli,N    UNION ALL SELECTlia,N    UNION ALL SELECTlian,N    UNION ALL SELECTliang,N    UNION ALL SELECTliao,N    UNION ALL SELECTlie,N    UNION ALL SELECTlin,N--轥拎    UNION ALL SELECTling,N    UNION ALL SELECTliu,N--瓼甅囖咯    UNION ALL SELECTlong,N    UNION ALL SELECTlou,N    UNION ALL SELECTlu,N    UNION ALL SELECTlv,N    UNION ALL SELECTluan,N    UNION ALL SELECTlue,N    UNION ALL SELECTlun,N    UNION ALL SELECTluo,N    UNION ALL SELECTma,N    UNION ALL SELECTmai,N    UNION ALL SELECTman,N    UNION ALL SELECTmang,N    UNION ALL SELECTmao,N    UNION ALL SELECTme,N--癦呅    UNION ALL SELECTmei,N    UNION ALL SELECTmen,N    UNION ALL SELECTmeng,N--霿踎    UNION ALL SELECTmi,N    UNION ALL SELECTmian,N    UNION ALL SELECTmiao,N    UNION ALL SELECTmie,N--鱴瓱    UNION ALL SELECTmin,N    UNION ALL SELECTming,N    UNION ALL SELECTmiu,N    UNION ALL SELECTmo,N--耱乮    UNION ALL SELECTmou,N--麰蟱    UNION ALL SELECTmu,N    UNION ALL SELECTna,N    UNION ALL SELECTnai,N    UNION ALL SELECTnan,N    UNION ALL SELECTnang,N    UNION ALL SELECTnao,N    UNION ALL SELECTne,N    UNION ALL SELECTnei,N--嫩焾    UNION ALL SELECTnen,N    UNION ALL SELECTneng,N--莻嗯鈪銰啱    UNION ALL SELECTni,N    UNION ALL SELECTnian,N    UNION ALL SELECTniang,N    UNION ALL SELECTniao,N    UNION ALL SELECTnie,N    UNION ALL SELECTnin,N    UNION ALL SELECTning,N    UNION ALL SELECTniu,N    UNION ALL SELECTnong,N    UNION ALL SELECTnou,N    UNION ALL SELECTnu,N    UNION ALL SELECTnv,N    UNION ALL SELECTnue,N    UNION ALL SELECTnuan,N--硸黁燶郍    UNION ALL SELECTnuo,N    UNION ALL SELECTo,N--毮夞乯鞰    UNION ALL SELECTou,N    UNION ALL SELECTpa,N    UNION ALL SELECTpai,N--鎃磗    UNION ALL SELECTpan,N    UNION ALL SELECTpang,N    UNION ALL SELECTpao,N    UNION ALL SELECTpei,N    UNION ALL SELECTpen,N    UNION ALL SELECTpeng,N--浌巼闏乶喸    UNION ALL SELECTpi,N    UNION ALL SELECTpian,N    UNION ALL SELECTpiao,N    UNION ALL SELECTpie,N    UNION ALL SELECTpin,N    UNION ALL SELECTping,N    UNION ALL SELECTpo,N    UNION ALL SELECTpou,N--兺哛    UNION ALL SELECTpu,N    UNION ALL SELECTqi,N    UNION ALL SELECTqia,N    UNION ALL SELECTqian,N    UNION ALL SELECTqiang,N--羻兛瓩    UNION ALL SELECTqiao,N    UNION ALL SELECTqie,N    UNION ALL SELECTqin,N    UNION ALL SELECTqing,N    UNION ALL SELECTqiong,N    UNION ALL SELECTqiu,N    UNION ALL SELECTqu,N    UNION ALL SELECTquan,N    UNION ALL SELECTque,N    UNION ALL SELECTqun,N    UNION ALL SELECTran,N    UNION ALL SELECTrang,N    UNION ALL SELECTrao,N    UNION ALL SELECTre,N    UNION ALL SELECTren,N    UNION ALL SELECTreng,N    UNION ALL SELECTri,N    UNION ALL SELECTrong,N    UNION ALL SELECTrou,N嶿    UNION ALL SELECTru,N    UNION ALL SELECTruan,N    UNION ALL SELECTrui,N    UNION ALL SELECTrun,N--橍挼    UNION ALL SELECTruo,N    UNION ALL SELECTsa,N--櫒栍    UNION ALL SELECTsai,N--簺虄    UNION ALL SELECTsan,N    UNION ALL SELECTsang,N    UNION ALL SELECTsao,N    UNION ALL SELECTse,N--裇聓    UNION ALL SELECTsen,N    UNION ALL SELECTseng,N--閪縇    UNION ALL SELECTsha,N    UNION ALL SELECTshai,N    UNION ALL SELECTshan,N    UNION ALL SELECTshang,N    UNION ALL SELECTshao,N    UNION ALL SELECTshe,N    UNION ALL SELECTshen,N    UNION ALL SELECTsheng,N    UNION ALL SELECTshi,N--鰘齛兙瓧    UNION ALL SELECTshou,N    UNION ALL SELECTshu,N    UNION ALL SELECTshua,N    UNION ALL SELECTshuai,N    UNION ALL SELECTshuan,N    UNION ALL SELECTshuang,N    UNION ALL SELECTshui,N    UNION ALL SELECTshun,N    UNION ALL SELECTshuo,N    UNION ALL SELECTsi,N--瀃螦乺    UNION ALL SELECTsong,N    UNION ALL SELECTsou,N    UNION ALL SELECTsu,N    UNION ALL SELECTsuan,N    UNION ALL SELECTsui,N    UNION ALL SELECTsun,N    UNION ALL SELECTsuo,N    UNION ALL SELECTta,N--躢襨    UNION ALL SELECTtai,N    UNION ALL SELECTtan,N    UNION ALL SELECTtang,N    UNION ALL SELECTtao,N--討畓    UNION ALL SELECTte,N    UNION ALL SELECTteng,N--霯唞朰    UNION ALL SELECTti,N    UNION ALL SELECTtian,N    UNION ALL SELECTtiao,N    UNION ALL SELECTtie,N    UNION ALL SELECTting,N--濎乭    UNION ALL SELECTtong,N    UNION ALL SELECTtou,N    UNION ALL SELECTtu,N    UNION ALL SELECTtuan,N    UNION ALL SELECTtui,N    UNION ALL SELECTtun,N    UNION ALL SELECTtuo,N    UNION ALL SELECTwa,N    UNION ALL SELECTwai,N    UNION ALL SELECTwan,N    UNION ALL SELECTwang,N    UNION ALL SELECTwei,N    UNION ALL SELECTwen,N    UNION ALL SELECTweng,N    UNION ALL SELECTwo,N    UNION ALL SELECTwu,N    UNION ALL SELECTxi,N    UNION ALL SELECTxia,N    UNION ALL SELECTxian,N    UNION ALL SELECTxiang,N    UNION ALL SELECTxiao,N    UNION ALL SELECTxie,N    UNION ALL SELECTxin,N    UNION ALL SELECTxing,N    UNION ALL SELECTxiong,N    UNION ALL SELECTxiu,N    UNION ALL SELECTxu,N    UNION ALL SELECTxuan,N    UNION ALL SELECTxue,N    UNION ALL SELECTxun,N    UNION ALL SELECTya,N    UNION ALL SELECTyan,N    UNION ALL SELECTyang,N    UNION ALL SELECTyao,N    UNION ALL SELECTye,N--鸈膶岃    UNION ALL SELECTyi,N    UNION ALL SELECTyin,N    UNION ALL SELECTying,N    UNION ALL SELECTyo,N    UNION ALL SELECTyong,N    UNION ALL SELECTyou,N    UNION ALL SELECTyu,N    UNION ALL SELECTyuan,N    UNION ALL SELECTyue,N    UNION ALL SELECTyun,N    UNION ALL SELECTza,N    UNION ALL SELECTzai,N    UNION ALL SELECTzan,N    UNION ALL SELECTzang,N    UNION ALL SELECTzao,N    UNION ALL SELECTze,N    UNION ALL SELECTzei,N    UNION ALL SELECTzen,N    UNION ALL SELECTzeng,N    UNION ALL SELECTzha,N    UNION ALL SELECTzhai,N    UNION ALL SELECTzhan,N    UNION ALL SELECTzhang,N    UNION ALL SELECTzhao,N    UNION ALL SELECTzhe,N    UNION ALL SELECTzhen,N    UNION ALL SELECTzheng,N    UNION ALL SELECTzhi,N    UNION ALL SELECTzhong,N    UNION ALL SELECTzhou,N    UNION ALL SELECTzhu,N    UNION ALL SELECTzhua,N    UNION ALL SELECTzhuai,N    UNION ALL SELECTzhuan,N    UNION ALL SELECTzhuang,N    UNION ALL SELECTzhui,N    UNION ALL SELECTzhun,N    UNION ALL SELECTzhuo,N    UNION ALL SELECTzi,N--漬唨    UNION ALL SELECTzong,N    UNION ALL SELECTzou,N    UNION ALL SELECTzu,N    UNION ALL SELECTzuan,N    UNION ALL SELECTzui,N    UNION ALL SELECTzun,N    UNION ALL SELECTzuo,N) t      WHERE  word >= @word COLLATE  Chinese_PRC_CS_AS_KS_WS      ORDER BY  word COLLATE  Chinese_PRC_CS_AS_KS_WS ASC)ELSE  @word END )     SET @i = @i + 1     END      RETURN  @pinyin END   GO
View Code
技术分享
/****** Object:  UserDefinedFunction [dbo].[fun_getAbbFirstPY]    Script Date: 01/08/2017 14:28:53 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOcreate   FUNCTION  [dbo].[fun_getAbbFirstPY](@str nvarchar(4000) ) RETURNS  nvarchar(4000) AS  BEGIN    DECLARE @word nchar(1),@PY nvarchar(4000)   set @PY=‘‘   WHILE len(@str)>0   BEGIN        set @word=left(@str,1)     --如果非汉字字符,返回原字符     set @PY=@PY+(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 B,N簿                              union all select C,N                      union all select D,N                      union all select E,N                      union all select F,N                      union all select G,N                      union all select H,N                      union all select J,N                      union all select K,N                      union all select L,N                      union all select M,N                      union all select N,N                      union all select O,N                      union all select P,N                      union all select Q,N                      union all select R,N                      union all select S,N                      union all select T,N                      union all select W,N                      union all select X,N                      union all select Y,N                      union all select Z,N                       ) T                     where word>=@word collate Chinese_PRC_CS_AS_KS_WS                     order by PY ASC                           )                        else @word                   end)     SET  @str=right(@str,len(@str)-1)     END     RETURN @PYEND GO
View Code

 

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

--初始化系统参数表

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

技术分享
INSERT INTO [PaaSCustDB].[dbo].[sysComOption]([Code] ,[ParentCode],[Version],[Status],[OptionType],[OptionName],[OptionCNName],[OptionDisplayName],[OptionAbbPYName],[OptionFullPYName],[OptionValueType],[OptionDisplayValue],[OptionValueNvarchar],[Comments],[Create_date],[Lastmodify_date])SELECT [code] ,[parentcode]    ,1    ,1 ,sysType001Region,dbo.fn_GetFullPinyin([Regionname],0),[Regionname],[Regionname],dbo.fun_getAbbFirstPY([Regionname]),dbo.fn_GetFullPinyin([Regionname],0),5,[Regionname],[Regionname],[parentRegionname]+:+[GPS],GETDATE(),GETDATE()FROM [PaaSCustDB].[dbo].[regionTemp]
View Code

 

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