Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
List tables in a database
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00966543
Message ID:
01405286
Views:
47
I hope I figured that out since it was 5 years since I posted the question :)

>>I am drawing a blank here. What command do I use in osql to list the tables in a database?
>>Also I can't remember what command I used to view fields (columns) in a table.
>>
>>If anyone knows of a great webpage where some of this type of information can be found I would appreciate if you could send me the link.
>>
>>Thanks,
>>Einar
>
>I know it's an old question, but the similar one was asked recently on another forum, so
>
>Posted by Nicola
>
>
>Create Procedure GetTablesAndColumns 
>(
>   @dbName  nvarchar(128) = NULL,
>   @tblName nvarchar(128) = Null
>) as Begin  
>  
>  declare @cmd nvarchar(max)
>
>  If @dbName is Null or @dbName='' 
>     Set @dbName=db_name()
>  Set @dbName = Quotename(@dbName)
>
>  If @tblName is not null and @tblName='' 
>     Set @tblName = NULL
>  
>  Set @cmd = N'
>Select t.name, c.* from ' + @dbName + '.sys.Tables t
> Inner Join ' + @dbName + '.sys.columns c on t.object_id=c.object_id            
> Where @tblName is Null or t.name=@tblName
> Order By t.name, c.column_id
> '
>
>  Exec sp_ExecuteSql @cmd, N'@tblName nvarchar(128)', @tblName
>End
>
>http://forums.asp.net/t/1433908.aspx
Semper ubi sub ubi.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform