0

I'm using sqlite3 for accessing database. I want to know the number of rows, the number of columns, and the name of the column from the queried result and database.

For example if I run SELECT * from table, and I get

id    name    number
--------------------
1     John    10
2     Jay     20

How can I know that the database has 2 rows, and 3 columns, and the number of columns are id/name/number?

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
jojo615
  • 43
  • 4
  • You better know your table structure right from the beginning. And you can get the number of rows from your resultset – juergen d Apr 09 '16 at 22:21
  • Possible duplicate of [Is there a Sqlite equivalent to MySQL's DESCRIBE \[table\]?](http://stackoverflow.com/questions/3330435/is-there-a-sqlite-equivalent-to-mysqls-describe-table) – pBuch Apr 09 '16 at 22:33

1 Answers1

0

Asking "how many cols" is the wrong question, because you normally "know" what data you are interested in.

You can count the number of rows using:

SELECT COUNT(*) FROM table;

The result will look like this:

COUNT(*)
---------
2

If you want a nicer display, use something like this:

SELECT COUNT(*) AS rows FROM table;

returning:

rows
-----
2
Stefan
  • 418
  • 5
  • 13