Friday, May 04, 2007

I've been looking for a simple way, to enumerate tables within a SQL Compact database,  using the following, I found out how -

http://msdn2.microsoft.com/en-us/library/aa274908(SQL.80).aspx

From this I came up with the following bits of SQL to get at useful bits of the SQL Compact database.

To list tables and views -

SELECT TABLE_NAME,TABLE_TYPE FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE in ('TABLE','VIEW') ORDER BY TABLE_NAME

 

To list fields within a table/view use -

SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='YOUR TABLEORVIEWNAME'

 

To list the keys in a given table/view use -

SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME='YOUR TABLEORVIEWNAME'

 

 

Technorati tags: ,
Comments are closed.

Theme design by Jelle Druyts

Pick a theme: