SQL-该值应使用哪种数据类型? [英] SQL - Which data type should be used for this value?

查看:78
本文介绍了SQL-该值应使用哪种数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想在数据库中存储一些值.我的值就是这样的111.000.000.00.我可以为该值使用哪种数据类型?

谢谢

Hi,

I Want to store some value in database. My value is like this 111.000.000.00. Which data type I can use for this value?

Thanks

推荐答案

显然是varchar(50)nvarchar(50),因为SQL中没有自定义数据类型可以将其存储为您自己的格式.

但是您可以在代码端限制值的格式.

[根据提供的信息进行更新]

更改您的SQL查询类似.
Obviously varchar(50) or nvarchar(50), Because there''s no custom datatype in SQL to store it in your own format.

But you could restrict the format of value at the code side.

[Update as per information provided]

Change your SQL Query Like.
string query = "select license_key from customer where imei_number='"+IMEI+"'";



因为IMEI是Varchar 数据类型,所以始终必须将其括在单引号小标题之间.如果是整数,则可以使用它.
[/更新]


如果有帮助,请 投票 接受答案 .



Becuase IMEI is a Varchar datatype so always it must be enclosed between single quote litrel. you can use it the way you have used if it is integer.
[/update]


Please vote and Accept Answer if it Helped.


vivekmahajan86写道:
vivekmahajan86 wrote:

我还使用了varchar(50),但是当我从数据库访问它时,它给出了错误. "System.Data.SqlClient.SqlException:.000000"附近的语法不正确".

i also used varchar(50), but it gives error when i access it from database. "System.Data.SqlClient.SqlException: Incorrect syntax near ''.000000''".



实际上,数据类型没有问题,因为您在C#.NET或VB.NET中编写的代码中存在数据类型,因为那里引发了异常.因此,您应该在问题中包含代码.

我的猜测是您可能在命令对象中包含与数据库表字段的数据类型不匹配的任何其他数据类型.例如(在数据库表中,数据类型为字段的varchar,但您可能会在前端代码的sqlcommand中提到nchar)



Actually there is no problem with the data type, it''s in your code which you have written in C#.NET or VB.NET because the exception raised there. So you should include the code in your question.

My guess is you may include any other datatype in your command object which doesn''t matched with database table field''s data type. For example (In DB table the datatype is varchar for a field but you might mentioned nchar in your sqlcommand in front-end code)


为此,您应使用
varchar数据类型.
For that you should use
varchar data type.


这篇关于SQL-该值应使用哪种数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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