Click here to Skip to main content
15,896,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
have a table without an id. Can I get the inbuilt id column in SQL Server?

It is possible or the question is wrong.

SQL
     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.
Posted
Comments
Gihan Liyanage 5-Sep-14 3:26am    
The value of VAL will be same for Same Units ?
[no name] 5-Sep-14 3:28am    
no
CPallini 5-Sep-14 3:37am    
Why don't you add an auto-increment field as ID?
[no name] 5-Sep-14 3:41am    
I don't have that ID and don't have rights to edit a table

You can create a View

SQL
CREATE VIEW view1
AS
 SELECT Row_Number() AS ID, Units, Val
 FROM Table1
 
Share this answer
 
v2
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900