Question

Can you tell us the names of all tables and table columns in the SQLite data dictionary?

Update:

I was using this information for a Basic4Android app I'm developing.

Here is the actual segment of coding I used:

' Create the PeopleToVisit table which holds lookup data about each visit.
'-------------------------------------------------------------------------
If SQL.ExecQuerySingleResult( _
    "SELECT count(name) FROM sqlite_master WHERE type='table' AND name='PeopleToVisit'") _
    = 0 Then

    ToastMessageShow("Creating the People to Visit table.", False)

    ' Create it now since it doesn't yet exist.
    '------------------------------------------
    SQL.ExecNonQuery("CREATE TABLE PeopleToVisit (" & _
        "Id INTEGER PRIMARY KEY, " & _
        "FirstName TEXT, " & _
        "LastName TEXT, " & _
        "Address1 TEXT, " & _
        "Address2 TEXT, " & _
        "City TEXT, " & _
        "State TEXT, " & _
        "Zip TEXT " & _
        ")")
End If

' New table columns for Version 1.2
'----------------------------------

' Coding for when new data columns need to be added to the database table.
'-------------------------------------------------------------------------
strCreateTableStatement = _
    SQL.ExecQuerySingleResult("SELECT sql " & _
                                "FROM sqlite_master " & _
                               "WHERE Type = 'table' AND name = 'PeopleToVisit'")

' Check if the new columns are in the table.
'-------------------------------------------
If strCreateTableStatement.IndexOf("PrimaryPhone TEXT") = -1 Then

    ' We need to add the new columns to the table.
    '---------------------------------------------
    SQL.ExecNonQuery("ALTER TABLE PeopleToVisit ADD COLUMN PrimaryPhone TEXT")
    SQL.ExecNonQuery("ALTER TABLE PeopleToVisit ADD COLUMN SecondaryPhone TEXT")
    SQL.ExecNonQuery("ALTER TABLE PeopleToVisit ADD COLUMN Email TEXT")
    SQL.ExecNonQuery("ALTER TABLE PeopleToVisit ADD COLUMN LastVisitNote TEXT")     
End If
Was it helpful?

Solution

To list all tables in a database

SELECT name FROM sqlite_master WHERE type='table'

To list all columns in a table

pragma table_info(table_name)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top