StefanE
StefanE

Reputation: 7630

Query to show Tables and Table definition in Starcounter Database

How can I get a list of table names and definitions by either SQL statement or code behind for the Starcounter DB?

Upvotes: 1

Views: 165

Answers (1)

k_rus
k_rus

Reputation: 3219

Metadata about created tables, their columns and indexes are stored in meta-data tables. Database classes are publicly exposed for corresponding meta-data tables.

Tables or types are described by Starcounter.Metadata.RawView and Starcounter.Metadata.ClrClass and both extends Starctouner.Metadata.Table. ClrClass contains description for loaded CLR classes only, while RawView describes all created tables. They include descriptions of user-defined classes/tables and metadata classes/tables.

For example, all loaded user-defined classes can be enumerated:

foreach(ClrClass c in Db.SQL<ClrClass>(
    "select c from Starcounter.Metadata.ClrClass c where Updatable = ?", true)) {
  Console.WriteLine(c.FullName);
}

Property Updatable of Table is true for user-defined tables and false for meta-data/system tables.

Properties or columns are described by Starcounter.Metadata.Member and its children. An example of enumerating all columns for all user-defined tables is:

foreach(Member m in Db.SQL<Member>(
    "select m from Column m, RawView v where m.Table = v and v.Updatable = ?",
    true)) {
  Console.WriteLine(m.Name);
}

Indexes are described by Starcounter.Metadata.Index and Starcounter.Metadata.IndexedColumn.

Currently it is one-to-one match between database classes and tables. However, this and metadata schema might change in future.

Upvotes: 3

Related Questions