如何将0001格式的ID插入数据库(即sqlserver 2005) [英] How to insert Id in 0001 format to database i.e. sqlserver 2005

查看:273
本文介绍了如何将0001格式的ID插入数据库(即sqlserver 2005)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将Id的值插入为0001,但在数据库中显示为1

我的数据字段中有7个字段

ID设置为Identity,可以显示这样的ID,而不是1
0001
否则我必须使用另一个不同名称的ID,且其数据类型为int

I m inserting value of Id as 0001 but it is showing 1 in database

I have 7 fields in my datafield

ID is set as Identity it is possible to show ID like this 0001 instead of 1

or I have to take another ID of different name with datatype int

推荐答案

数据类型int仅将其显示为数字.您无法更改它.您可以创建一个选择查询以将其显示为0001,但仅将其存储为1.
Datatype int will display it as a number only. There is no way you can change it. You can create a select query to show it as 0001, but it will be stored as 1 only.
select right('0000' + convert(varchar(4),yourField), 4) from yourTable


这篇关于如何将0001格式的ID插入数据库(即sqlserver 2005)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆