Column count in SQL
-
SELECT COUNT(1) AS RowCount FROM table
Unless you know where to look:
SELECT COUNT(1) AS ColumnCount
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME='tablename';
This should work from SQL server 2000 and MySQL 5 and upwards.
Differences between MSSQL and MySQL.
In MySQL you can add the TABLE_SCHEMA to the WHERE clause in order to define what database contains the table you are looking for, to count columns. In MSSQL it seems to only contain “dbo” which doesn’t help much.
There are most likely other places to look for that information, I just haven’t had any need for it yet. And if your user only has access to 1 database, you shouldn’t need it anyway.
Leave a Reply
Welcome to Thronic.com
Search this Site
Miscellaneous Links
Recent Articles
- Google-like search suggestion tool
- Linux Bash Color
- Resize a div layer with javascript
- Moving a div layer with javascript
- Web Galaxy » A sci-fi browser game
- Windows 7 on Asus Eee 900 PC
- IE and PHP sessions
- Wordpress 2.8.6 Spell Check Languages
- Reset MySQL Root Password
- Linux hosts file
- IdleGuard
- Column count in SQL
- String encryption in PHP
- Alphanumeric Captcha values in PHP
- Your own numeric Captcha in PHP
