SQL Server中的查询ID [英] Query ID in SQL server

查看:120
本文介绍了SQL Server中的查询ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好..

我正在查询Sql Server中的数据,我遇到了一个错误,我的意思是一个非常尴尬的回复。

i在我的表中有200条记录表ID介于1-200之间。现在的问题是,当我输入Id = 332时它也会显示我的记录,即使我没有任何ID 332



我尝试过:



这是我的查询

Hi Everyone..
I am querying data in Sql Server and i have face an error i mean a very awkward response.
i have 200 Records in my table and the Table id is in between 1-200. Now the problem is when i enter the Id = 332 it will also show me record even i don't have any id 332

What I have tried:

Here is my Query

Select MOSQUEID,NAME,CITY,POSTCODE,PHONE from tbl_mosque Where MOSQUEID=332

推荐答案

如果此查询:

If this query:
Select MOSQUEID,NAME,CITY,POSTCODE,PHONE from tbl_mosque Where MOSQUEID=332

返回任何记录,然后你的表中有一行或多行有一个332的MosqueId - 它不会发明这样的信息!



因此,首先查看查询返回的行,然后查看它返回的确切内容。将其与表格中的内容进行比较(使用SSMS查看内容)。

如果该行不存在,请检查您的连接字符串以及您正在使用的表格。



可能您正在使用IDENTITY列并假设有200个条目意味着IDENTITY值始终在1到200之间 - 但SQL不会重用值,所以如果删除行,再次INSERT它们将无法获得相同的ID值。

is returning any records, then you have one or more rows in your table which have a MosqueId of 332 - it will not invent such info!

So start by looking at the row(s) the query returns and see exactly what it is returning. Compare that to what is in the table (using SSMS to view the contents).
If the row doesn't exist, check your connection string and which table you are using.

It may be that you are using an IDENTITY column and assuming that having 200 entries implies that the IDENTITY values will always range from 1 to 200 - but SQL doesn't "reuse" values, so if you DELETE rows, and INSERT them again they will not get the same ID value.


这篇关于SQL Server中的查询ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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