{"id":8565,"date":"2026-09-09T12:00:00","date_gmt":"2026-09-09T10:00:00","guid":{"rendered":"https:\/\/www.newstechnology.eu\/it\/?p=8565"},"modified":"2026-09-08T22:07:13","modified_gmt":"2026-09-08T20:07:13","slug":"guida-a-sqlite-il-database-in-un-solo-file","status":"publish","type":"post","link":"https:\/\/www.newstechnology.eu\/it\/programmazione\/python\/guida-a-sqlite-il-database-in-un-solo-file.html","title":{"rendered":"Guida a SQLite: Il Database in un Solo File"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>SQLite<\/strong> \u00e8 il motore di database relazionale pi\u00f9 diffuso al mondo, ma funziona in modo radicalmente diverso rispetto a sistemi complessi come <a href=\"https:\/\/www.newstechnology.eu\/it\/virtualizzazione\/importare-database-mysql-in-un-contenitore-docker-mysql.html\" target=\"_blank\" rel=\"noopener\">MySQL<\/a> o PostgreSQL. La sua caratteristica principale \u00e8 l&#8217;architettura <strong>serverless<\/strong>: non richiede l&#8217;installazione di un server in background, configurazioni di rete, n\u00e9 la gestione di utenti e password.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">L&#8217;<strong>intero database<\/strong>, comprensivo di tabelle, indici e dati, \u00e8 <strong>racchiuso all&#8217;interno di un singolo file <\/strong>testuale sul tuo disco fisso (solitamente salvato con estensione .sqlite o .db).<\/p>\n\n\n\n<!--more-->\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"559\" src=\"https:\/\/www.newstechnology.eu\/it\/wp-content\/uploads\/2026\/09\/sqlite3-database-1024x559.webp\" alt=\"Sqlite3 il database racchiuso in un solo file.\" class=\"wp-image-8566\" srcset=\"https:\/\/www.newstechnology.eu\/it\/wp-content\/uploads\/2026\/09\/sqlite3-database-1024x559.webp 1024w, https:\/\/www.newstechnology.eu\/it\/wp-content\/uploads\/2026\/09\/sqlite3-database-300x164.webp 300w, https:\/\/www.newstechnology.eu\/it\/wp-content\/uploads\/2026\/09\/sqlite3-database-768x419.webp 768w, https:\/\/www.newstechnology.eu\/it\/wp-content\/uploads\/2026\/09\/sqlite3-database-1536x838.webp 1536w, https:\/\/www.newstechnology.eu\/it\/wp-content\/uploads\/2026\/09\/sqlite3-database-2048x1117.webp 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>A Cosa Potrebbe Servire un Database su Singolo File?<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Essendo leggero e portatile, SQLite non \u00e8 progettato per gestire le migliaia di scritture simultanee di un enorme e-commerce, ma eccelle in tantissimi altri scenari pratici:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Script e Web Scraper:<\/strong> \u00c8 perfetto per script di automazione che devono scansionare pagine web, raccogliere dati e memorizzarli in modo strutturato, garantendo che le informazioni non vadano perse in caso di interruzione improvvisa.<\/li>\n\n\n\n<li><strong>Sviluppo e Prototipazione:<\/strong> Permette di testare rapidamente la logica di backend e le operazioni CRUD di un&#8217;applicazione lavorando in locale, senza dover configurare un database esterno.<\/li>\n\n\n\n<li><strong>Applicazioni Desktop e Mobile:<\/strong> \u00c8 il <em>motore predefinito di Android<\/em>, iOS e di moltissimi programmi desktop per salvare le preferenze, i log e i dati dell&#8217;utente.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Come Utilizzarlo: Un Esempio in Python<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">L&#8217;integrazione di SQLite con molti linguaggi di programmazione \u00e8 nativa. In Python non \u00e8 nemmeno necessario installare pacchetti esterni tramite pip. Ecco un esempio base che illustra come connettersi, creare una tabella, inserire dati e leggerli:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import sqlite3<br \/><br \/># 1. Si collega al file (se il file non esiste, lo crea automaticamente)<br \/>connessione = sqlite3.connect(\"miodatabase.sqlite\")<br \/>cursore = connessione.cursor()<br \/><br \/># 2. Crea una tabella<br \/>cursore.execute(\"\"\"<br \/>&nbsp; &nbsp; CREATE TABLE IF NOT EXISTS utenti (<br \/>&nbsp; &nbsp; &nbsp; &nbsp; id INTEGER PRIMARY KEY AUTOINCREMENT,<br \/>&nbsp; &nbsp; &nbsp; &nbsp; nome TEXT NOT NULL,<br \/>&nbsp; &nbsp; &nbsp; &nbsp; ruolo TEXT<br \/>&nbsp; &nbsp; )<br \/>\"\"\")<br \/><br \/># 3. Inserisce un record<br \/>cursore.execute(\"INSERT INTO utenti (nome, ruolo) VALUES (?, ?)\", (\"Mario Rossi\", \"Amministratore\"))<br \/>connessione.commit()<br \/><br \/># 4. Rilegge e stampa i dati<br \/>cursore.execute(\"SELECT * FROM utenti\")<br \/>print(cursore.fetchall())<br \/><br \/># 5. Chiude la connessione<br \/>connessione.close()<br \/><br \/><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Strumenti Semplici per Consultare il File SQLite<\/strong> <\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Una volta che il tuo codice ha generato il <strong>file .sqlite<\/strong>, non devi per forza usare script di programmazione per analizzarne il contenuto. Esistono ottimi software visivi gratuiti:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. <a href=\"https:\/\/sqlitebrowser.org\/\" target=\"_blank\" rel=\"noopener nofollow\">DB Browser<\/a> for SQLite (Ideale per iniziare)<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u00c8 lo strumento visivo pi\u00f9 semplice e leggero, disponibile sia per Windows che per Linux (Ubuntu). Ti permette di aprire il tuo file .sqlite con un click, sfogliare i dati in formato tabellare simile a Excel, modificare manualmente le celle e testare query SQL.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. <a href=\"https:\/\/dbeaver.io\/\" target=\"_blank\" rel=\"noopener nofollow\">DBeaver<\/a><\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Uno strumento open-source pi\u00f9 avanzato e multipiattaforma. Funziona in modo eccellente su ambienti Linux e Windows. \u00c8 altamente consigliato se, oltre a SQLite, ti capita di lavorare anche con database pi\u00f9 grandi, in quanto ti offre un&#8217;unica interfaccia unificata.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. La Riga di Comando (CLI)<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Se usi regolarmente Ubuntu o una distribuzione Linux e preferisci muoverti da terminale, puoi esplorare il database in modo nativo. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Ti basta installare il pacchetto base <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em>sudo apt-get install sqlite<\/em><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">e digitare <strong>sqlite3 miodatabase.sqlite<\/strong>. Da quel momento, potrai lanciare comandi rapidi come .tables per elencare le tabelle o scrivere direttamente le tue SELECT.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Qui di seguito troverai i comandi per usare sqlite3 da command line.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sqlite> .help\n.archive ...             Manage SQL archives\n.auth ON|OFF             Show authorizer callbacks\n.backup ?DB? FILE        Backup DB (default \"main\") to FILE\n.bail on|off             Stop after hitting an error.  Default OFF\n.cd DIRECTORY            Change the working directory to DIRECTORY\n.changes on|off          Show number of rows changed by SQL\n.check GLOB              Fail if output since .testcase does not match\n.clone NEWDB             Clone data into NEWDB from the existing database\n.connection &#91;close] &#91;#]  Open or close an auxiliary database connection\n.databases               List names and files of attached databases\n.dbconfig ?op? ?val?     List or change sqlite3_db_config() options\n.dbinfo ?DB?             Show status information about the database\n.dump ?OBJECTS?          Render database content as SQL\n.echo on|off             Turn command echo on or off\n.eqp on|off|full|...     Enable or disable automatic EXPLAIN QUERY PLAN\n.excel                   Display the output of next command in spreadsheet\n.exit ?CODE?             Exit this program with return-code CODE\n.expert                  EXPERIMENTAL. Suggest indexes for queries\n.explain ?on|off|auto?   Change the EXPLAIN formatting mode.  Default: auto\n.filectrl CMD ...        Run various sqlite3_file_control() operations\n.fullschema ?--indent?   Show schema and the content of sqlite_stat tables\n.headers on|off          Turn display of headers on or off\n.help ?-all? ?PATTERN?   Show help text for PATTERN\n.import FILE TABLE       Import data from FILE into TABLE\n.indexes ?TABLE?         Show names of indexes\n.limit ?LIMIT? ?VAL?     Display or change the value of an SQLITE_LIMIT\n.lint OPTIONS            Report potential schema issues.\n.load FILE ?ENTRY?       Load an extension library\n.log FILE|on|off         Turn logging on or off.  FILE can be stderr\/stdout\n.mode MODE ?OPTIONS?     Set output mode\n.nonce STRING            Suspend safe mode for one command if nonce matches\n.nullvalue STRING        Use STRING in place of NULL values\n.once ?OPTIONS? ?FILE?   Output for the next SQL command only to FILE\n.open ?OPTIONS? ?FILE?   Close existing database and reopen FILE\n.output ?FILE?           Send output to FILE or stdout if FILE is omitted\n.parameter CMD ...       Manage SQL parameter bindings\n.print STRING...         Print literal STRING\n.progress N              Invoke progress handler after every N opcodes\n.prompt MAIN CONTINUE    Replace the standard prompts\n.quit                    Stop interpreting input stream, exit if primary.\n.read FILE               Read input from FILE or command output\n.recover                 Recover as much data as possible from corrupt db.\n.restore ?DB? FILE       Restore content of DB (default \"main\") from FILE\n.save ?OPTIONS? FILE     Write database to FILE (an alias for .backup ...)\n.scanstats on|off|est    Turn sqlite3_stmt_scanstatus() metrics on or off\n.schema ?PATTERN?        Show the CREATE statements matching PATTERN\n.separator COL ?ROW?     Change the column and row separators\n.session ?NAME? CMD ...  Create or control sessions\n.sha3sum ...             Compute a SHA3 hash of database content\n.shell CMD ARGS...       Run CMD ARGS... in a system shell\n.show                    Show the current values for various settings\n.stats ?ARG?             Show stats or turn stats on or off\n.system CMD ARGS...      Run CMD ARGS... in a system shell\n.tables ?TABLE?          List names of tables matching LIKE pattern TABLE\n.timeout MS              Try opening locked tables for MS milliseconds\n.timer on|off            Turn SQL timer on or off\n.trace ?OPTIONS?         Output each SQL statement as it is run\n.version                 Show source, library and compiler versions\n.vfsinfo ?AUX?           Information about the top-level VFS\n.vfslist                 List all available VFSes\n.vfsname ?AUX?           Print the name of the VFS stack\n.width NUM1 NUM2 ...     Set minimum column widths for columnar output<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>SQLite \u00e8 il motore di database relazionale pi\u00f9 diffuso al mondo, ma funziona in modo radicalmente diverso rispetto a sistemi complessi come MySQL o PostgreSQL. La sua caratteristica principale \u00e8 l&#8217;architettura serverless: non richiede l&#8217;installazione di un server in background, configurazioni di rete, n\u00e9 la gestione di utenti e password. L&#8217;intero database, comprensivo di tabelle, &#8230; <a title=\"Guida a SQLite: Il Database in un Solo File\" class=\"read-more\" href=\"https:\/\/www.newstechnology.eu\/it\/programmazione\/python\/guida-a-sqlite-il-database-in-un-solo-file.html\" aria-label=\"Per saperne di pi\u00f9 su Guida a SQLite: Il Database in un Solo File\">Leggi tutto<\/a><\/p>\n","protected":false},"author":1,"featured_media":8566,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"wpai_meta_description":"","footnotes":""},"categories":[1710],"tags":[301,1900,1899,45,1411,1902,1898,295],"class_list":["post-8565","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-database","tag-database-in-un-file","tag-database-sqlite3","tag-linux","tag-python","tag-semplice-database","tag-sqlite3","tag-ubuntu"],"_links":{"self":[{"href":"https:\/\/www.newstechnology.eu\/it\/wp-json\/wp\/v2\/posts\/8565","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.newstechnology.eu\/it\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.newstechnology.eu\/it\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.newstechnology.eu\/it\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.newstechnology.eu\/it\/wp-json\/wp\/v2\/comments?post=8565"}],"version-history":[{"count":1,"href":"https:\/\/www.newstechnology.eu\/it\/wp-json\/wp\/v2\/posts\/8565\/revisions"}],"predecessor-version":[{"id":8567,"href":"https:\/\/www.newstechnology.eu\/it\/wp-json\/wp\/v2\/posts\/8565\/revisions\/8567"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.newstechnology.eu\/it\/wp-json\/wp\/v2\/media\/8566"}],"wp:attachment":[{"href":"https:\/\/www.newstechnology.eu\/it\/wp-json\/wp\/v2\/media?parent=8565"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.newstechnology.eu\/it\/wp-json\/wp\/v2\/categories?post=8565"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.newstechnology.eu\/it\/wp-json\/wp\/v2\/tags?post=8565"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}