Skip to main content
gamedev.net
🔒 Locked

[web] SQL + Column Names

Started by kag1 Feb 8, 2005 at 12:03 PM 3 replies 1.4k views
Original Post
kag1
kag1
Hello, i'm at college and can't connect to a MS SQL Server from here with my front end programs I have. (I think the ports are blocked maybe)..but I can connect from a webserver I have with the use of ASP..so I was kinda thinkin of maybe making my own little frontend. I have been looking through SQL tutorial sites and such, but can't find a way to return the column names of a specific table...or find out what tables are in the database without already knowing the table name.. Can anyone help me out?
C-Junkie
C-Junkie
I recall from my mysql days using something like "show databases" and "show tables"

no clue if it's the same for mssql.
Lazzar
Lazzar
in oracle you can use:

table names:
select table_name from user_tables;

column names:
select column_name from user_tab_columns whre table_name = 'MYTABLE'


Lazzar
---------------------------------------------------------if god gave us the source code, we could change the world!
Michalson
Michalson
There are two ways.

One is by reading from the system (sys*) tables. For example this will return a list of all tables in the database:

SELECT name FROM sysobjects WHERE xtype='U'

I suggest you lookup the documentation on MSDN (or buy a copy SQL Server to get the big poster) for more information (you can read everything about the database from the sys* tables, including tables, columns, indexes, contraints, etc).

The other way (probably easier if you are using ASP) is by using an ADOX catalog. For example to do what we did above (note that this is actual ASP script, using VBScript as the language):
Set Connection = Server.CreateObject("ADODB.Connection")Connection.Open "blah"Set Catalog = Server.CreateObject("ADOX.Catalog")Catalog.ActiveConnection = ConnectionFor Each Table in Catalog.TablesResponse.Write Table.Name & "
"Next


As before, you can get all the information you want, just read the properties (lookup the reference on MSDN for all the properties)
evolutional
evolutional
Also: sp_help will show all objects in the database. Supply it an object name (eg: MyTable) and it'll show a bunch of info about it, including the column specs... But Michalson's way is probably the most practical.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.