I want to get Schema for a table with name "Petro" in SQL SErver after initializing connectionString, I use this Code
conn.open();
conn.getSchema("Tables");
but it returns schema for all the tables. I only want the Petro schema. What should I do?
In Object Explorer, expand the Databases folder. Expand the database in which to create the new database schema. Right-click the Security folder, point to New, and select Schema. In the Schema - New dialog box, on the General page, enter a name for the new schema in the Schema name box.
A table schema is a named schema for a set of Query Tables that completely defines the structure of those Query Tables, and ensures that all Query Tables in the set are identically defined. A table schema includes the table structure of a Query Table, as well as its primary index and secondary indices (if any).
You can retrieve the schema in following way:
string sql = "select * from Petro WHERE 1 = 0";
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataReader reader = cmd.ExecuteReader();
DataTable schema = reader.GetSchemaTable();
SQL Server solution:
There is a store procedure called sp_columns
. When you run that procedure with the table's name as a parameter, it will return the schema just for that table.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With