2011-11-27 77 views
2

你能告訴我們SQLite數據字典中所有表和表列的名稱嗎?SQLite數據字典表和列

更新:

我利用這些信息爲Basic4Android應用我開發。

這裏是編碼的實際段我用:

' 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 

回答

3

要列出數據庫

SELECT name FROM sqlite_master WHERE type='table' 

所有表要列出所有列在表中

pragma table_info(table_name) 
+0

感謝答案。我使用sqlite_master來查找信息。請參閱我對該帖子的更新。 –

+0

您可以像'SQL.ExecQuery(「pragma table_info('PeopleToVisit')」)這樣的'SELECT'語句'' – tidwall

+0

''使用'pragma table_info(table_name)'感謝SQL語句示例。我會嘗試。 :-) –