yeago Posted March 21, 2006 Share Posted March 21, 2006 I am attempting to get the microsoft SQL equivalent of "show columns from table" from MySQL.HOW? Quote Link to comment https://forums.phpfreaks.com/topic/5440-how-to-return-a-tables-column-names/ Share on other sites More sharing options...
Barand Posted May 14, 2006 Share Posted May 14, 2006 Here's one way[code]$result = mssql_query("SELECT TOP 1 * FROM tablename");$row = mssql_fetch_assoc($result);foreach ($row as $colname => $value) { echo $colname . '<BR />';}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/5440-how-to-return-a-tables-column-names/#findComment-35812 Share on other sites More sharing options...
GeoffOs Posted May 17, 2006 Share Posted May 17, 2006 You can use a query like this:[code]select * from information_schema.columns where table_name = '<<your table name>>'[/code] Quote Link to comment https://forums.phpfreaks.com/topic/5440-how-to-return-a-tables-column-names/#findComment-36640 Share on other sites More sharing options...
fractil Posted June 23, 2006 Share Posted June 23, 2006 Continuing with GeoffOs post, I find it helpful to include the database name in the FROM clause.just do a select on the information_schema.COLUMNS table:select column_namefrom <dbname>.information_schema.columnswhere table_name = '<tablename>'see: [a href=\"http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_ia-iz_4pbn.asp\" target=\"_blank\"]http://msdn.microsoft.com/library/default...._ia-iz_4pbn.asp[/a]Cheers! Quote Link to comment https://forums.phpfreaks.com/topic/5440-how-to-return-a-tables-column-names/#findComment-48809 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.