如何在SQL Server中获取第一列值 [英] How to get the First column value in SQL Server

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

问题描述

有一张没有id的表。我可以在SQL Server中获取内置的id列吗?



这可能或问题是错误的。



have a table without an id. Can I get the inbuilt id column in SQL Server?

It is possible or the question is wrong.

     Units     val
-------------------
1   mg |ZNS|   NULL
2   mg |ZNS|   NULL
3   Mg |ZNS|   NULL
4   mg |ZNS|   NULL
5   Mg |ZNS|   NULL
6   mg |ZNS|   NULL
7   mgd|ZNS|   NULL
8   mg |ZNS|   NULL
9   mgm|ZNS|   NULL
10  Mg |ZNS|   NULL





我必须更新



I have to update a

val

列。我怎样才能做到这一点?单位列有一些重复值。



建议我得到一个解决方案



先谢谢。

column. How can I do this? The units column having some duplicate values.

Suggest me to get a solution

Thanks in Advance.

推荐答案

你可以创建一个视图



You can create a View

CREATE VIEW view1
AS
 SELECT Row_Number() AS ID, Units, Val
 FROM Table1






据我所知,从Oracle开始,SQL Server不维护ROWID概念。



您可以尝试以下步骤...



1.创建一个包含一个标识列的新表。

2.将原始表中的所有数据转储到新表中。

3.由于您在新的表中具有唯一ID表,现在您可以根据需要更新详细信息。

4.删除原始t能够。

5.用原始名称重命名新表。





以上所有步骤均可缩短如果你在表格中引入身份栏。





希望这会对你有所帮助。



干杯
Hi,

As far as i know, SQL Server does not maintain ROWID concept as of Oracle.

You can try these steps...

1. Create a new table with one identity column.
2. Dump all the data from original table to new table.
3. Since you have unique id in new table, now you can update the details as required.
4. Drop the original table.
5. Rename the new table with original name.


All above steps can be shortened if you introduce identity column in your table.


Hope this will help you.

Cheers


这篇关于如何在SQL Server中获取第一列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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