简体   繁体   中英

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:

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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