如何在SQL Server中的多个表中选择同时输入/更新的所有记录?

时间:2022-10-01 09:27:55

is there someone out there who can help me select multiple records that were entered/updated on different tables on the same time in the SQL Server database. Do you think this is possible or not?

是否有人可以帮助我选择在SQL Server数据库中同时在不同表上输入/更新的多个记录。你认为这是可能的吗?

Your help is highly appreciated, thanks!

非常感谢您的帮助,谢谢!

4 个解决方案

#1


Does your table have a date/time-stamp column of type DATETIME??

你的表是否有DATETIME类型的日期/时间戳列?

Otherwise you're probably out of luck....

否则你可能会运气不好......

Marc

#2


Hm... could it be something as simple as

嗯...可能是一件简单的事情

SELECT   * 
FROM     MyTable 
WHERE    CreatedDate = 'the date you are interested in'

or

SELECT   * 
FROM     MyTable 
GROUP BY CreatedDate
HAVING   COUNT(*) > 1

?

#3


if you are inside the insert trigger, you can query the inserted pseudo-table.

如果您在插入触发器内,则可以查询插入的伪表。

#4


If the DATETIME columns are all named the same, you can generate the queries like

如果DATETIME列的名称相同,则可以生成类似的查询

select
    'select * from '
        + t.name 
        + ' where UpdateDate = ''2009-05-01''' as SelectStatement
from sys.tables as t

Or if the DATETIME column name is not static, you can do something along these lines:

或者,如果DATETIME列名称不是静态的,您可以按以下方式执行操作:

select
    'select * from ' + t.name 
        + ' where ' + c.name + ' = ''2009-05-01''' as SelectStatement
from sys.tables as t join sys.columns as c on t.object_id=c.object_id
where c.system_type_id = (select system_type_id from sys.types where name = 'datetime')

#1


Does your table have a date/time-stamp column of type DATETIME??

你的表是否有DATETIME类型的日期/时间戳列?

Otherwise you're probably out of luck....

否则你可能会运气不好......

Marc

#2


Hm... could it be something as simple as

嗯...可能是一件简单的事情

SELECT   * 
FROM     MyTable 
WHERE    CreatedDate = 'the date you are interested in'

or

SELECT   * 
FROM     MyTable 
GROUP BY CreatedDate
HAVING   COUNT(*) > 1

?

#3


if you are inside the insert trigger, you can query the inserted pseudo-table.

如果您在插入触发器内,则可以查询插入的伪表。

#4


If the DATETIME columns are all named the same, you can generate the queries like

如果DATETIME列的名称相同,则可以生成类似的查询

select
    'select * from '
        + t.name 
        + ' where UpdateDate = ''2009-05-01''' as SelectStatement
from sys.tables as t

Or if the DATETIME column name is not static, you can do something along these lines:

或者,如果DATETIME列名称不是静态的,您可以按以下方式执行操作:

select
    'select * from ' + t.name 
        + ' where ' + c.name + ' = ''2009-05-01''' as SelectStatement
from sys.tables as t join sys.columns as c on t.object_id=c.object_id
where c.system_type_id = (select system_type_id from sys.types where name = 'datetime')