-
SQL SERVER 如何处理带字母的自增列--【叶子】
-
- /*
- id col
-
- AB00001 a
- AB00002 b
-
- */
-
-
-
-
- if object_id('[macotb]') is not null
- drop table [macotb]
- create table [macotb] (id varchar(7),col varchar(1))
- insert into [macotb]
- select 'AB00001','a' union all
- select 'AB00002','b'
-
- declare @max varchar(7)
- select @max='AB'+right('00000'+ltrim(max(replace(id,'AB','')+1)),5) from [macotb]
- insert into [macotb] select @max,'c'
-
- select * from [macotb]
- /*
- id col
-
- AB00001 a
- AB00002 b
- AB00003 c
- */
-
-
- if object_id('[macotb]') is not null
- drop table [macotb]
-
- create table [macotb] ([no] int identity,id varchar(7),col varchar(1))
- insert into [macotb]
- select 'AB00001','a' union all
- select 'AB00002','b'
-
- insert into [macotb](col) select 'c'
- update [macotb]
- set id='AB'+right('00000'+ltrim([no]),5) where [no]=@@identity
-
- select id,col from [macotb]
- /*
- id col
-
- AB00001 a
- AB00002 b
- AB00003 c
- */
-
-
- if object_id('[macotb]') is not null
- drop table [macotb]
-
- create table [macotb]
- (
- [no] int identity,
- id as ('AB'+right('00000'+ltrim([no]),5)),
- col varchar(1)
- )
-
- insert into [macotb](col) select 'a' union all select 'b'
-
- select id,col from [macotb]
- /*
- id col
-
- AB00001 a
- AB00002 b
- */
-
- insert into [macotb](col) select 'c' union all select 'd'
- select id,col from [macotb]
- /*
- id col
-
- AB00001 a
- AB00002 b
- AB00003 c
- AB00004 d
- */
-
-
-
相关阅读:
springloud系列搭建注册中心
在生产环境下禁用swagger
consul怎么在windows下安装
linux上传与下载
使用git将本地代码提交到码云上去
springboot整合activemq(三)配置文件
springboot整合activemq(二),消费均匀分析
Python3学习之路~3.2 递归、函数式编程、高阶函数、匿名函数、嵌套函数
Python3学习之路~3.1 函数基本语法及特性、返回值、参数、局部与全局变量
Python3学习之路~2.9 字符编码与转码
-
原文地址:https://www.cnblogs.com/douqiumiao/p/3365313.html
Copyright © 2020-2023
润新知