Welcome to Dream.In.Code
Getting Help is Easy!

Join 132,456 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,390 people online right now. Registration is fast and FREE... Join Now!




select/get column names of a specified table

2 Pages V  1 2 >  
Reply to this topicStart new topic

select/get column names of a specified table, sql server

Quentin
post 12 Dec, 2001 - 01:48 AM
Post #1


New D.I.C Head

*
Joined: 26 Nov, 2001
Posts: 24

hi there

i'm working on an sql server.

example: i got a table "user" with columns "usID","usNAME" and "usPWD"

i know it works, but i don't know the sql statement to SELECT all the column names of a specified table (here: "user")

SELECT * FROM sysobjects WHERE type = 'U' - with this statement i got every table in my database.. so i think it will work in a way like that..

do you have an idea?

thanks

User is offlineProfile CardPM

Go to the top of the page

The Neoracle
post 12 Dec, 2001 - 10:20 AM
Post #2


Check, check, 1, 2.

Group Icon
Joined: 30 Mar, 2001
Posts: 4,069



Thanked 1 times
My Contributions


SELECT "usID" FROM "user"

The syntax is the same as what you had before but instead if the * character (which means everything) you just specify what you want

User is offlineProfile CardPM

Go to the top of the page

klewlis
post 12 Dec, 2001 - 12:19 PM
Post #3


cur tu me vexas?

*****
Joined: 9 Nov, 2001
Posts: 1,723

QUOTE
Quote: from The Neoracle on 12:20 pm on Dec. 12, 2001
SELECT "usID" FROM "user"

Except without the quotes around the table and column names. So if you want all the columns in the table "user" then do:
SELECT * FROM user

and add a WHERE clause if you like, and whatever else.

User is offlineProfile CardPM

Go to the top of the page

Quentin
post 13 Dec, 2001 - 07:08 AM
Post #4


New D.I.C Head

*
Joined: 26 Nov, 2001
Posts: 24

arg... that's not what i wanted...

example: SELECT * FROM sysobjects WHERE type = 'U'  returns a recordset that consists of these entries:

name
----------------------
User
Articles
Links
Comments

so out put rs("name") while not EOF is "UserArticlesLinksComments"

- the table names in the database...

and if "user" consits of the attributes "usname, usid, uspwd" i want to have a sql query that returns

name
----------
usname
usid
uspwd


understand now?

btw... i know sql pretty good... but no idea about that...

(Edited by Quentin at 10:13 am on Dec. 13, 2001)

User is offlineProfile CardPM

Go to the top of the page

klewlis
post 13 Dec, 2001 - 07:17 AM
Post #5


cur tu me vexas?

*****
Joined: 9 Nov, 2001
Posts: 1,723

oh, you're looking for the column *names*, not the column *contents*...

interesting. I've never done that before. I'll think about that... just out of curiosity, why would you need to do that? don't you know the names of all your table columns?
(if you don't, I worry about the application... ;)

User is offlineProfile CardPM

Go to the top of the page

Quentin
post 13 Dec, 2001 - 07:21 AM
Post #6


New D.I.C Head

*
Joined: 26 Nov, 2001
Posts: 24

want to make an admin tool
and its very useful...

for example a data-manipulation-file... select your table, enter a sql statement and execute it... or list all your data of 1 table with input fields for editing... would be a 100% dynamic story to edit files with a database...

:)

User is offlineProfile CardPM

Go to the top of the page

klewlis
post 13 Dec, 2001 - 07:22 AM
Post #7


cur tu me vexas?

*****
Joined: 9 Nov, 2001
Posts: 1,723

oh... just be really careful with allowing people to enter SQL statements in... you can lose your entire db that way ;)
User is offlineProfile CardPM

Go to the top of the page

Quentin
post 13 Dec, 2001 - 07:25 AM
Post #8


New D.I.C Head

*
Joined: 26 Nov, 2001
Posts: 24

admin tool... normally placed on a nt-secured folder on your web app.... and only access for people who know what to do...

i think i'm pretty sure about what i do ;)

User is offlineProfile CardPM

Go to the top of the page

The Neoracle
post 13 Dec, 2001 - 07:27 AM
Post #9


Check, check, 1, 2.

Group Icon
Joined: 30 Mar, 2001
Posts: 4,069



Thanked 1 times
My Contributions


You do know that there are lots of one's that are already prebuilt?  Like PHPMyAdmin?  You could always download one of those and see how they do it?!?
User is offlineProfile CardPM

Go to the top of the page

Quentin
post 13 Dec, 2001 - 09:29 AM
Post #10


New D.I.C Head

*
Joined: 26 Nov, 2001
Posts: 24

uhh... i don't like code of others, always a hard way to read...

like the snitz forum or the comersus e-shop...

just the sql statement would help me more than a whole finished product...

but it's a good idea, i'll have a look...

User is offlineProfile CardPM

Go to the top of the page

The Neoracle
post 13 Dec, 2001 - 12:21 PM
Post #11


Check, check, 1, 2.

Group Icon
Joined: 30 Mar, 2001
Posts: 4,069



Thanked 1 times
My Contributions


Ok, I got out the ol MySql book. I'm not sure if this is MySql specific but this is what I found:

SHOW COLUMNS FROM tbl_name [FROM db_name] [LIKE pattern]


I hope that helps, I put a sticky on the page if you need more info.

Peace,

User is offlineProfile CardPM

Go to the top of the page

Quentin
post 13 Dec, 2001 - 12:23 PM
Post #12


New D.I.C Head

*
Joined: 26 Nov, 2001
Posts: 24

thanks a lot :), i'll try tomorrow (localtime: 21:24) at work..

stay tuned ;)

User is offlineProfile CardPM

Go to the top of the page

2 Pages V  1 2 >
Fast ReplyReply to this topicStart new topic
Time is now: 11/22/08 12:08PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month