SQL Server Question:
I have a table with appx. 1000 already existing rows, and 5 columns
How can I update the value at row Y in column ?
I don't have any keys or conditions for the where.
SQL Server Question:
I have a table with appx. 1000 already existing rows, and 5 columns
How can I update the value at row Y in column ?
I don't have any keys or conditions for the where.
WITH q AS (
SELECT m.*, ROW_NUMBER() OVER (ORDER BY column) AS rn
FROM mytable m
)
UPDATE q
SET mycol = 'newvalue'
WHERE rn = @Y
Note that in SQL
there is no concept of implicit row order.
There is no n'th row
unless you define the ordering condition (column
in example above).
In this table:
col1 col2
1 2
2 1
, the row (1, 2)
is first when ordering by col1
, and second when ordering by col2
.
First, you add a primary key, whether you already have a candidate key (possibly even a composite key) or choose to use a surrogate key. You can then use that as your criteria in your where clause.