繁体   English   中英

从C#中的SQL Create语句检索表名

[英]Retrieve table name from SQL Create statement in C#

假设我有从我的代码外部执行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();

是否可以确定新创建的表的名称而无需直接从sql语句字符串中进行解析?

我认为这不是最好的解决方案。但是,您可以使用此查询在数据库中创建/更改最后一个表。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM