[英]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.