473,386 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

List of all tables in a database

Hello,

How do you get a list of all tables in a sql server database using C#?

Thanks
Maz.
Nov 17 '05 #1
2 1971
you can use sp_help 'DBName' and it will return a dataset with all the
information about a database.
I only use a subset of that information:

Create procedure GetTables

select [name] from (
select

'Name' = o.name,
'Owner' = user_name(uid),
'Object_type' = substring(v.name,5,31)

from sysobjects o, master.dbo.spt_values v
where o.xtype = substring(v.name,1,2) collate database_default and
v.type = 'O9T'
)z

where object_type= 'user table'
order by Object_type desc, Name asc

go

Create procedure GetColumnNames
(
@TableName varchar(255)
)

As

Declare @objname nvarchar(776)
Declare @objID int
Declare @dbname sysname
declare @sysobj_type char(2)

set @objname = @TableName

select @dbname = parsename(@objname,3)

select @objid = id, @sysobj_type = xtype from sysobjects where id =
object_id(@objname)

select
'Column_name' = name,
'Type' = type_name(xusertype)
from syscolumns where id = @objid and number = 0 order by type, colid

go
"Maziar Aflatoun" <ma***@rogers.com> wrote in message
news:zI********************@rogers.com...
Hello,

How do you get a list of all tables in a sql server database using C#?

Thanks
Maz.

Nov 17 '05 #2
you can use:

"SELECT name FROM sysobjects WHERE xtype = 'U' "

That will give you a listing of all user tables.

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: tom | last post by:
I am new to SQL administration. >From a list of IDs that are the primary key in one table (i.e. Customer Table), I want to make changes in tables that use those IDs as a foreign key. ...
0
by: Miguelito Bain | last post by:
hi everybody- i've got a conundrum... i inherited some old databases, and i'm trying to convert them. i run office xp with access 2002, and all of the databases i manage are either in 97...
3
by: Robertf987 | last post by:
Well, I think I've described what I want to do in the title here. In the database, I have two main tables that contain the main data for the database. One for group expenditures, another for...
2
by: Lysander | last post by:
I have not seen this feature documented before, so I thought I would share it with you, as I will be using it in a later article. For a combo or list box, the source data is normally a...
1
by: anuragvatsa | last post by:
hi, how to write query to select project estimated effort,actual effort spent,%usage of project effort,%completion of project,ratio of %work completion to % effort consumed FOR 1. during the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.