|
-
I am trying to get a count of the number of columns in a table
I am trying to get a column count of the number of columns in a table called Soloists; the database is myCDDB.
I understand that the information is to be found in INFORMATION_SCHEMA.COLUMNS and I think that the following select statement should be used:
Select Count(*) From INFORMATION_SCHEMA.COLUMNS Where TABLE_NAME='Soloists' and TABLE_SCHEMA = 'myCDDB'"
but how do I get a count value from this statement.
-
Your query is already doing exactly what you need.
SELECT COUNT(*)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'myCDDB'
AND TABLE_NAME = 'Soloists';
COUNT(*) returns a single scalar value ? the number of columns in the table. Just execute the query and read the result.
If you need the value programmatically (e.g., in a stored routine), use SELECT ... INTO:
SELECT COUNT(*)
INTO @col_count
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'myCDDB'
AND TABLE_NAME = 'Soloists';
For ad-hoc checks, tools like dbForge Studio for MySQL also expose the column list and count directly in the table designer/properties, which avoids querying INFORMATION_SCHEMA altogether.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|