在 SQLite 中顯示錶

Preet Sanghavi 2022年7月12日
在 SQLite 中顯示錶

在本教程中,我們將學習如何在 SQLite 中顯示錶。

在 SQLite 中顯示錶是執行資料庫操作的重要步驟。我們將通過多種方式在 SQLite 中顯示錶。

在 SQLite 中顯示錶

讓我們看看第一種顯示錶格的方法所涉及的步驟。

  • 列出資料庫中的表。
    .tables
    
  • 讓我們看看我們資料庫中表的外觀。
    .schema table_name
    
  • 列印整個表格。
    SELECT * from table_name;
    

輔助函式 .tables.schema 不會搜尋 ATTACHED 資料庫; 相反,他們查詢主資料庫的 SQLITE MASTER 表。

  • 你可以使用以下方法搜尋附加的表格:
    ATTACH demo_file.db AS demo_db;
    
  • 我們需要編寫以下語句來顯示這些檔案:
    SELECT name FROM demo_db.sqlite_master WHERE type='table';
    
  • 我們還必須注意臨時表也不會出現。為了展示它們,我們需要列出 sqlite_temp_master
    SELECT name FROM sqlite_temp_master WHERE type='table';
    

使用上述方式,我們可以使用不同的技術在 SQLite 中顯示錶。

Preet Sanghavi avatar Preet Sanghavi avatar

Preet writes his thoughts about programming in a simplified manner to help others learn better. With thorough research, his articles offer descriptive and easy to understand solutions.

LinkedIn GitHub

相關文章 - Python SQLite