sql server查询插入dateofbirth和emailid? [英] sql server query to insert dateofbirth and emailid ?

查看:81
本文介绍了sql server查询插入dateofbirth和emailid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

create table mst_reg

(id int not null identity(1,1),

Name varchar(80),

Lastname varchar (80),

父名varchar(80),

Qualifiaction varchar(80),

Emailid varchar(80),

Phno int







插入mst_reg值('aqib','javid ','nija​​mudeen','BTechIT','aqib55 @ live.com',965557017796)





执行插入查询时它显示的表中的数据



消息8115,等级16,状态2,行1

将表达式转换为数据的算术溢出错误类型int。

该声明已被终止。请帮帮我

create table mst_reg
(id int not null identity(1,1),
Name varchar(80),
Lastname varchar(80),
Fathername varchar(80),
Qualifiaction varchar(80),
Emailid varchar(80),
Phno int
)


insert into mst_reg values('aqib','javid','nijamudeen','BTechIT','aqib55@live.com',965557017796)


while executing the query to insert the data ito the table it shows
"
Msg 8115, Level 16, State 2, Line 1
Arithmetic overflow error converting expression to data type int.
The statement has been terminated." please help me

推荐答案

当你进行INSERT查询时,总是列出要插入数据的列是一个非常好的主意,或者SQL只会从当前的第一列开始,然后插入你的值。

在你的情况下,第一列是一个IDENTITY列 - 所以即使你提供了一个整数值,它仍会抛出异常。

尝试:

When you do an INSERT query, it's a very good idea to always list the columns you are going to insert the data into, or SQL will just start with the current first column and insert your values starting with that.
In your case, that first column is an IDENTITY column - so even if you did supply an integer value, it still would throw an exception.
Try:
INSERT INTO mst_reg (Name, Lastname, Fathername, Qualifiaction, Emailid, Phno) VALUES ('aqib', 'javid', 'nijamudeen', 'BTechIT', 'aqib55@live.com', 965557017796)

但是,如果你这样做,请这通过高级语言,记得使用参数化查询!不要连接字符串以构建SQL命令。它让您对意外或故意的SQL注入攻击持开放态度,这可能会破坏您的整个数据库。使用参数化查询

But please, if you are doing this via a high level language, remember to use parameterized queries! Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead


您还将phno字段存储为整数,存储在数字字段中的数字大小有限制,将其存储为文本。
You are also storing the phno field as an integer, there is a limit on the size of number stored in numeric fields, store it as text.




你可以让你的手机不超过10位数,因为错误本身表明算术溢出。

这意味着int有一些限制。您可以将该数据类型更改为bigint



创建表格mst_reg





id bigint not null identity(1,1),

名称varchar(80),

姓氏varchar(80),

父名varchar (80),

Qualifiaction varchar(80),

Emailid varchar(80),

DOB DATETIME NOT NULL,

Phno bigint



Hi,
You can have your Phone no up to 10 digit, As Error itself suggest that Arithmetic overflow.
It means int have some limit. you can change that datatype to bigint

create table mst_reg
(

id bigint not null identity(1,1),
Name varchar(80),
Lastname varchar(80),
Fathername varchar(80),
Qualifiaction varchar(80),
Emailid varchar(80),
DOB DATETIME NOT NULL,
Phno bigint

)


这篇关于sql server查询插入dateofbirth和emailid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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