Question

I have a low knowledge on DBs and particularly on SQL server 2008.

I have to work on a big database and I have no document to help me to understand what each table contains.

What I want to do is to display a kind of prototype of the database.

For example :

Table1 - Col1 ; Col2 ;Col2

Table2 - Col1 ; Col2 ;Col3 ...

I just want to display the name (maybe the type) of each column for each table. I already display a schema but this is really impossible to read (so many tables).

Apologizes if this question was already asked.

Thanks

Was it helpful?

Solution

Try this query I have just written it hopefully will give you much of the information you are looking for

SELECT  ss.name AS [Schema_Name]
       ,so.name AS Table_Name
       ,c.name  AS [Column_Name]
       ,st.name AS  [Data_Type]

FROM sys.all_objects so 
        INNER JOIN sys.columns c
ON so.object_id = c.object_id
INNER JOIN sys.schemas ss
ON so.[schema_id] = ss.[schema_id]
INNER JOIN sys.systypes st
ON c.user_type_id = st.xusertype
WHERE so.type = 'U'

OTHER TIPS

I always try to come up with the simplest solution. A couple easy ones come to mind.

1 - The sp_help command gives you a wealth information. The first call below executes it for one table, and the second call below executes it for all tables.

-- Use corect database
USE AdventureWorks2012
GO

-- One table
sp_help 'person.person'
GO

-- All tables
DECLARE @STMT VARCHAR(128) = 'EXEC SP_HELP ' + char(39) + '?' + CHAR(39);
EXEC SP_MSFOREACHTABLE @STMT
GO

enter image description here

2 - While this gives you textual information on data types and relationships, it does not supply it in graphical form.

SSMS has a diagram feature that will show the relationships between the tables. I created a diagram for a couple of the tables in the person schema and one in the sales schema.

The downside of this utility is that the data types are not shown in the picture. However, opening the properties pages will allow you to drill into a field (column) and find all the about it.

enter image description here

3 - Last but not least, you can always purchase a third party tool that does it better.

I have a several blog talks using the AUTOS toy database. The diagram below was created from Oracle's ERD package. The nice advantage of this tool is that both the data types and relationships are shown in the picture.

In short, it fixes the short comings of the SSMS diagram tool. Also, given a DDL script from DB2, ORACLE or SQL Server, it will generate a diagram.

In short, picture a solution that fits your budget and you are comfortable with.

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top