Solved

VS2010 - Data Access for a Project

Posted on 2014-04-07
6
380 Views
Last Modified: 2016-02-10
Hi and thanks,

I am very new to all this.

I would like to:

Determine what databases/tables are being accessed/updated within a project.

Apparently there is no documentation yet on the project(s).

I have not been assigned anything yet, but would like to be a little propared for the near future when I do.

I just am looking for some direction at this point???

Thanks
0
Comment
Question by:Amour22015
6 Comments
 
LVL 22

Assisted Solution

by:plusone3055
plusone3055 earned 70 total points
ID: 39984041
well the best way ot determine this is to look within the source code of the project/ application.

unless there is documentation on the application/project.  it could prove difficult.
of course you can always take guesses and then look at the databases and tables.

for instance
if you have an application that has 4 textboxews

first name
last name
DOB
phone number

you can always enter some data in and them run a search string query against the databases with the data you entered to determine that tables/columns  the data went into.  :)
0
 
LVL 6

Assisted Solution

by:Dulton
Dulton earned 180 total points
ID: 39984111
SQL Profiler may give you some insight in real-time. It isn't going to be a blueprint, but it can show you what is happening at that instant. (which means if you are curious, you can setup the profiler, execute the task/command you're questioning and then review the profiler trace to see what SQL did.

http://msdn.microsoft.com/en-us/library/ff650699.aspx

There are also some 3rd party tools which will document/diagram the dbs for you. I have no personal experience, but maybe others do! I won't promote any one over another since I've never used one.
0
 

Author Comment

by:Amour22015
ID: 39984395
Looks like I might have to do this the hard way and get all the table information within a database.


So far I have this:
USE Your Database Name
SELECT name FROM sys.tables
ORDER BY name

This works to bring up a list of Tables in a DB

BUT:
How can I get this to either get copied to word or printed???

Thanks
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 39985783
I suggest you look at something like Red Gate's SQL Doc.  This tool will document all your schema and code.
0
 
LVL 6

Accepted Solution

by:
Dulton earned 180 total points
ID: 39985811
If you're using Sql Server Management Studio, you can right click in the top-left of the output grid and either copy/paste into excel or word (I'd recommend excel for this) or rather choose "save as" and export the results as a tab delimited text file.

if you must have a text output, try this code here. if you toggle the parameter @OrderByScheama, you can change whether the schema begins the table name or is rather included in () at the end of the table name.

DECLARE @objId INT
DECLARE @t_name VARCHAR(260)    
DECLARE @c_name VARCHAR(128)
DECLARE @c_pos INT
DECLARE @d_type VARCHAR(128)
DECLARE @max_length INT
DECLARE @precision INT
DECLARE @nullable VARCHAR(8)
DECLARE @k_type VARCHAR(128)
DECLARE @OrderBySchema BIT = 1

 
DECLARE UserTbls CURSOR  FOR

        SELECT CASE  @OrderBySchema WHEN 1  THEN s.[name] + '.'  + t.[name]
                                                           ELSE t.[name] + ' ('  + s.[name] + ')'  END AS [t_name]
              ,c.[name] AS [c_name]
                  ,c.[column_id] AS [c_position]
                  ,t1.[name]
                  ,c.[max_length]
                  ,c.[precision]
                  ,CASE  WHEN c.[is_nullable] = 1 THEN  'NULL' ELSE 'NOT NULL' END AS  [Nullable]
                  ,k.[type_desc]
          FROM sys.[all_columns] AS c
INNER JOIN sys.[tables] AS t
                ON c.[object_id] = t.[object_id]
INNER JOIN sys.[schemas] AS s
            ON t.[schema_id] = s.[schema_id]
INNER JOIN sys.[types] as t1
                ON c.[user_type_id] = t1.[user_type_id]
LEFT JOIN [sys].[key_constraints] AS k
                ON t.[object_id] = k.[parent_object_id]
           AND c.[column_id] = k.[unique_index_id]
        WHERE t.[type] = 'U'            --user tables only
  ORDER BY  [t_name]
                  ,[c_position]

 
OPEN UserTbls
        FETCH NEXT  FROM UserTbls
                  INTO @t_name
                          ,@c_name
                          ,@c_pos
                          ,@d_type
                          ,@max_length
                          ,@precision
                          ,@nullable
                          ,@k_type

                WHILE @@FETCH_STATUS = 0
                        BEGIN
                        IF @c_pos  = 1
                                BEGIN
                                        PRINT ''
                                        PRINT @t_name  + Replicate(' ',10) + '(MaxLength,Precision)'
                                        PRINT Replicate('-',50)         
                                END                     

                                PRINT Replicate(' ',4) + @c_name  + ' ' 
                                                                           + @d_type +  '(' 
                                                                           + Cast(@max_length AS VARCHAR(10)) + ','
                                                                           + Cast(@precision AS VARCHAR(10)) + ') '
                                                                           + @nullable
                                                                           + Isnull(' ' + @k_type,'') 

                        FETCH NEXT  FROM UserTbls 
                                INTO @t_name
                                    ,@c_name
                                    ,@c_pos
                                    ,@d_type
                                    ,@max_length
                                    ,@precision
                                    ,@nullable
                                        ,@k_type

                        END

CLOSE UserTbls
DEALLOCATE userTbls

Open in new window

0
 

Author Closing Comment

by:Amour22015
ID: 39985876
Thanks to all...
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here's a requirements document template for an integration project (also known as Extract-Transform-Load or ETL) based on my development experience as an SQL Server Information Services (SSIS) developer over the years.
I have a large data set and a SSIS package. How can I load this file in multi threading?
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now