[英]Retrieve table name from SQL Create statement in C#
Say I have code that executes a sql create table statement from outside my code, like so: 假设我有从我的代码外部执行sql create table语句的代码,如下所示:
SqlConnection connection = new SqlConnection(aConnectionString);
connection.Open();
string createTable = System.IO.File.ReadAllText("CreateTable.sql");
SqlCommand command = new SqlCommand(createTable, connection);
command.ExecuteNonQuery();
Is it possible to determine the name of the newly created table WITHOUT parsing it directly from the sql statement string? 是否可以确定新创建的表的名称而无需直接从sql语句字符串中进行解析?
This is not the best solution I think ... But you can get the last table created / changed in your database with this query. 我认为这不是最好的解决方案。但是,您可以使用此查询在数据库中创建/更改最后一个表。
select name,type,type_desc, create_date, modify_date from sys.objects
where convert(varchar,modify_date,101) = convert(varchar,getdate(),101) AND type = 'U'
order by modify_date desc
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.