验证字段以防止接受SQL中的错误数据 [英] Validating Field To Prevent From Accepting Bad data in SQL

查看:80
本文介绍了验证字段以防止接受SQL中的错误数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我需要知道如何通过验证接受错误数据的某些列来将列值插入表中.

例如,如果我有一列名为"MobileNo"的列,并且有人试图在"MobileNo"字段中插入超过10位数字的值,那么如何检查验证(使用IF-ELSE或其他方法).

我的查询(SP)在这里:

Hi ALL,

I need to know how to insert the column values into a table by validating some of the columns which is accepting a bad data.

For e.g., If I have a column called "MobileNo" and some one tries to insert the value that exceeds 10 digits in "MobileNo" field, then how to check for the validation(using IF-ELSE or whatever).

My Query(SP) is here:

INSERT INTO dbo.FTA_ReportFileDumpNew

select A.MobileNo,A.CustomerName,A.Product,A.Suk_Type,A.FTR_Date,A.FTA_Date,
A.Sim_No,A.IMSI_No,A.Retailer_No,A.RetailerName,A.MacMobile_No,A.MacPrimary,
A.MacLocation,A.HUB,A.CombinedZone,A.TM_Name,A.TM_Number,A.RETAILER_SMS_DATE,
A.CUSTOMER_SMS_DATE,A.[TAT/Hrs],A.[TAT/Mins],A.MinuteWiseData,0,@UploadedBy,GETDATE()
FROM dbo.FTA_ReportFileDump A where exists
 (select 1 from FTA_ReportTbView B
 where A.MobileNo = B.MobileNo)





任何帮助或建议都非常可取.

问候,

Raj





Any help or suggestion greatly appreciable.

Regards,

Raj

推荐答案

已阅读 SQL检查约束!阅读:
SQL检查约束 [ SQL CHECK约束-2 [
Have a read on SQL Check Constraints! Read:
SQL CHECK Constraints[^]
SQL CHECK Constraint - 2[^]

Instead of having any logic in query to handle it, you can have check constraints in place and go ahead smoothly.
Other way would be to handle it in UI itself.


这篇关于验证字段以防止接受SQL中的错误数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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