在sql server 2005中更新了哪些行 [英] in which rows updated in sql server 2005
问题描述
亲爱的朋友
我在实施程序时遇到一些问题。实际问题如下: -
考虑我的表用户: -
以下属性: -
Dear Friend
I have some problem when implementing program.The actual problem is as follows :-
Consider my table User:-
The following attributes:-
userid name email address phone company designation
1 a a@gmail.com nagpur 1 x developer
2 b b@gmail.com pune 2 y dba
3 c c@gmail.com mumbai 3 z engineers
4 d d@gmail.com nagpur 4 y developer
如果您更新了用户ID 1和3中的任何信息,就像: -
butes: -
if you have updated any information in the user id 1 and 3 just like :-
butes:-
userid name email address phone company designation
1 a a@gmail.com pune 2 y manager
2 b b@gmail.com pune 2 y dba
3 c c@gmail.com nagpur 5 x developer
4 d d@gmail.com nagpur 4 y developer
这两个用户ID信息已更新,所以我的问题是如何理解用户这两行是否更新?有任何疑问请尽快给我提供信息。
感谢先进!!
This two userid information updated so my question is "How to understand user this two rows updated or not" ? is any query please give me information as soon as possible .
Thanks in advanced !!
推荐答案
如果你想知道什么是行更新然后你可以用两种方式来做..
1.在更新语句之前写一个select语句选择要更新的行像...
If You want to know what are the rows updated then u can use do it in two ways..
1. Write a select Statement before Update Statement selecting rows which will be updated Like...
Select Columnname from TableName Where Condition
Update TableName set column= something Where Condition
2.您可以使用 TRIGGER 更新该特定表并将这些记录保存到一些新表中......
选中此链接以获取触发器 [ ^ ]
2. U can use a TRIGGER for update of that Particular Table and save those records in to some new table...
Check this link for Triggers[^]
CREATE TRIGGER TriggerName
ON TableName
AFTER UPDATE
AS
IF ( UPDATE (ColumnName))
BEGIN
--Do Something
END;
如果你只是想要要了解受声明影响的行数,您可以使用 @@ RowCount
...
If you just want to Know the no of Rows affected by a statement u can use @@RowCount
...
Create Table #Test(id Int, value Nvarchar(40))
Insert into #Test
Select 1,'Value1' Union All
Select 2,'Value2' Union All
Select 3,'Value3' Union All
Select 4,'Value4'
Select @@ROWCOUNT [RowCount After Insert] -- Returns 4
Select * From #Test
Select @@RowCount [RowCount After Select] -- Returns 4
Update #Test Set id=1 where id<4
Select @@RowCount [RowCount After Update] -- Returns 3
Update #Test Set id=1 where id=0
Select @@ROWCOUNT -- Returns 0
Drop Table #Test
如果列是主键/外键,你可以获取列更新的日期
you can fetch column update's date if column is primary key/foreign key like this
Select * From sys.objects where type_desc in('PRIMARY_KEY_CONSTRAINT','FOREIGN_KEY_CONSTRAINT')
Order by modify_date Desc
希望这有助于...
Hope this Helps...
我认为你的问题是 - 如何理解你的查询更新了哪些行(而不是行数) )。我没有遇到任何这样的查询,它会提供已经更新的行列表。
你能尝试在表格中添加一个新列吗?更新的时间戳,并通过查看时间来确定哪些行已更新。显然,这只适用于开发环境,但不适用于具有多个用户的环境。您仍然可以通过添加包含LastUpdatedBy和LastUpdatedDate列的2列来尝试。
I think your question is - how to understand which rows have been updated by your query (and not the number of rows). I haven't come across any such query which would provide the list of rows which have been updated.
Can you try adding a new column to the table which would display the Updated timestamp and make out which rows have been updated by looking at the time. Obviously this will work only in a dev kind of environment but would not in an environment with multiple users. You can still give it a try by adding 2 columns which contain the "LastUpdatedBy" and "LastUpdatedDate" columns.
这篇关于在sql server 2005中更新了哪些行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!