access sql check if an index exists before creating
I'm creating an index on table in an 开发者_JAVA技巧access database, programmatically:
CREATE INDEX ind ON tableA (columnb);
Is there a way I can do a "if not exists" before trying to create the index?
Thanks!
I do not think you can be quite so neat with Access, but here are a few notes. I know nothing of C#, so the following is based only on some knowledge of Access.
string connectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\docs\\some.mdb";
OleDbConnection con = new OleDbConnection(connectionString);
con.Open();
//Number of restriction columns: 5
//Restriction columns: TABLE_CATALOG, TABLE_SCHEMA, INDEX_NAME, TYPE, TABLE_NAME
string[] restrictions = new string[5];
restrictions[2] = "SomeKey";
restrictions[4] = "SomeTable";
System.Data.DataTable table = con.GetSchema("Indexes",restrictions);
References
http://msdn.microsoft.com/en-us/library/cc668764.aspx
http://msdn.microsoft.com/en-us/library/ms135852.aspx
http://msdn.microsoft.com/en-us/library/ms709712(v=vs.85).aspx
精彩评论