The Adapdev.Data.Schema namespace allows you to retrieve the schema for a specific database. This includes information on all tables and columns, primary and foreign keys, column names and types, etc.
Database schema structure is composed of three main classes:
DatabaseSchema
TableSchema
ColumnSchema
Below is a UML diagram that shows the classes and their relationships

Iterating through the values is straight-forward:
DatabaseSchema dbSchema = ... // retrieve the schema foreach(TableSchema table in dbSchema.SortedTables.Values) { Console.WriteLine("Table: " + table.Name); foreach(ColumnSchema column in table.SortedColumns.Values) { Console.WriteLine(column.Name); } }
You can quickly retrieve the schema for a database using the SchemaBuilder class. It currently supports the following database types
Sql Server
Oracle
Access
mySql
To retrieve a schema, simply use the CreateDatabaseSchema method.
For all databases, except for mySql, you must pass in an OLEDB connection string. For mySql, you must pass in a native mySQL connection string.
// Retrieve the schema for Sql Server Northwind
DatabaseSchema ds = SchemaBuilder.CreateDatabaseSchema(
"Provider=sqloledb;Data Source=localhost;" +
Initial Catalog=northwind;User Id=sa;Password=;",
Adapdev.Data.DbType.SQLSERVER,
Adapdev.Data.DbProviderType.SQLSERVER);// Retrieve a schema for mySQL
DatabaseSchema ds = SchemaBuilder.CreateDatabaseSchema(
"Data Source=localhost;Database=codus_test;User ID=;Password=;",
Adapdev.Data.DbType.MYSQL,
Adapdev.Data.DbProviderType.MYSQL);In many cases, you'll want to persist the schema to a file store. The DatabaseSchema is serializable, so just use the Serializer class to store and retreive it:
DatabaseSchema schema = ... // create your database schema
Serializer.SerializeToBinary(schema, "schema.bin");
In cases where you have two schemas for the same database (a previous version with saved changes and the current schema) you can run a comparison. The comparison will create a new schema, with all new tables / columns added and all removed tables / columns taken out.
So, for example, if SchemaOld has TableD has been removed in SchemaNew, then TableD wouldn't be present in the resulting schema. Likewise, if SchemaOld doesn't have TableA, but it's present in SchemaNew, it will be added to the resultant schema.
To do a comparison, use the CompareDatabaseSchemas command:
DatabaseSchema schemaOld = ... // create the old schema
DatabaseSchema schemaNew = ... // create the new schema
CompareDatabaseSchemas compare = new CompareDatabaseSchemas(schemaOld, schemaNew);
DatabaseSchema result = compare.Compare(); // compares and merges both