I'm looking at creating a basic ORM (purely for fun), and was wondering, is there a way to return the list of tables in a database and also the fields for every table?
Using this, I want to be able to loop through the result set (in C#) and then say for each table in the result set, do this (e.g. use reflection to make a class that will do or contain xyz).
Further to this, what are some good online blogs for SQL Server? I know this question is really about using system SPs and databases in Sql Server, and I am ok with general queries, so I'm interested in some blogs which cover this sort of functionality.
Thanks
Get list of all the tables and the fields in database:
Get list of all the fields in table:
SELECT * FROM INFORMATION_SCHEMA.COLUMNS
for get allSELECT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS
for get all table name. Try it on sqlserver,Tables ::
columns ::
or
This will get you all the user created tables:
To get the cols:
Also, I find http://www.sqlservercentral.com/ to be a pretty good db resource.
Is this what you are looking for:
Using OBJECT CATALOG VIEWS
Using INFORMATION SCHEMA VIEWS
Reference : My Blog - http://dbalink.wordpress.com/2008/10/24/querying-the-object-catalog-and-information-schema-views/