C#SqlConnection查询时态表 [英] C# SqlConnection Querying Temporal tables
问题描述
我有一个临时表Employee
,其中EmployeeHistory
作为其历史表.
I have a temporal table Employee
with EmployeeHistory
as its history table.
在C#中,我正在使用SqlConnection
从SQL Server查询数据,以了解雇员的全部历史记录.
In C#, I am using SqlConnection
to query the data from SQL Server for the entire history of an employee.
var data = Conn.ExecuteReader("select * from Employee e FOR SYSTEM_TIME ALL WHERE e.Id=15");
这将引发错误:
FOR附近的语法不正确
Incorrect syntax near FOR
那么,我们如何使用SqlConnection
在C#中查询历史数据以获取临时表?
So, how do we query history data for a temporal table in C# using SqlConnection
?
推荐答案
问题是您使用的表别名是e
,还是该错误.不要以为您可以使用表别名.将其更改为
Problem is you are using table alias e
and so the error. Don't think you can use table alias. change it to
select * from Employee FOR SYSTEM_TIME ALL WHERE Id=15
如果您查看文档临时表,您将看到该语法根本不显示使用表别名.而是必须使用整个表名.
If you check the documentation Querying Data in a System-Versioned Temporal Table (OR) Temporal Tables you will see that the syntax doesn't show the use of table alias at all. Rather you will have to use the entire table name.
也请参阅此相关文章 查看全文