{"id":227,"date":"2017-12-10T11:57:34","date_gmt":"2017-12-10T11:57:34","guid":{"rendered":"https:\/\/blinksql.com\/?p=227"},"modified":"2017-12-10T11:57:34","modified_gmt":"2017-12-10T11:57:34","slug":"sqlite","status":"publish","type":"post","link":"https:\/\/blinksql.com\/?p=227","title":{"rendered":"SQLite"},"content":{"rendered":"<p>-&gt; SQLite is an open source, zero-configuration, self-contained, stand alone, transaction relational database engine designed to be embedded into an application.<\/p>\n<p>-&gt;\u00a0SQLite does not have a separate server process. It reads and writes directly to ordinary disk files.<\/p>\n<p>-&gt;\u00a0SQLite doesn&#8217;t require configuration. No setup or administration required.he<\/p>\n<p class=\"h1\"><strong>Create Database:<\/strong><\/p>\n<p class=\"n\">The sqlite3 command is used to create database. But, if the database does not exist then a new database file with the given name will be created automatically.<\/p>\n<p><strong>cmd:sqlite3 test.db<\/strong><\/p>\n<p>-&gt; To see the databases:<\/p>\n<p><strong>cmd:\u00a0.databases\u00a0\u00a0<\/strong><\/p>\n<p>-&gt; To quit from the database<\/p>\n<p><strong>cmd: .quit<\/strong><\/p>\n<p>-&gt;dump Command:The .dump dot command is used to export complete database in a text file by using SQlite command at command prompt.<\/p>\n<p><strong>cmd: sqlite3 test.db\u00a0.dump\u00a0&gt; test.sql\u00a0\u00a0<\/strong><\/p>\n<p class=\"h3\"><strong>Attach database:<\/strong><\/p>\n<p>To select a particular database and after using this command, all SQLite statements will be executed under the attached database.<\/p>\n<p><strong>cmd:ATTACH\u00a0<span class=\"keyword\">DATABASE<\/span>\u00a0<span class=\"string\">&#8216;DatabaseName&#8217;<\/span>\u00a0<span class=\"keyword\">As<\/span>\u00a0<span class=\"string\">&#8216;Alias-Name&#8217;<\/span>;\u00a0 \u00a0<\/strong><\/p>\n<p>Note: It will also create a database if the database is not already present, otherwise it will only attach a database file name with the logical database Alias-Name.<\/p>\n<p class=\"h1\"><strong>Detach Database:<\/strong><\/p>\n<p>It is used to detach the alias-named database from a database connection which was previously attached by using ATTACH statement.<\/p>\n<p><strong>cmd: DETACH\u00a0<span class=\"keyword\">DATABASE<\/span>\u00a0<span class=\"string\">&#8216;Alias-Name&#8217;<\/span>\u00a0\u00a0<\/strong><\/p>\n<p>To see the list tables:<\/p>\n<p><strong>cmd: .tables<\/strong><\/p>\n<p class=\"h1\"><strong>SQLite Import:<\/strong><\/p>\n<p>-&gt; Import a CSV file into SQLite table by using sqlite3 tool and .import command. This command accepts a file name, and a table name.<\/p>\n<p>-&gt;\u00a0Here, file name is the file from where the data is fetched and the table name is the table where the data will be imported into. In the absence of the table, it will create the table automatically according to the data in CSV file.<\/p>\n<p><strong>cmd: .mode\u00a0csv <\/strong><\/p>\n<p><strong>cmd:.import\u00a0\/Users\/javatpoint1\/Desktop\/sqlite\/student.csv\u00a0EMPLOYEE\u00a0<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.javatpoint.com\/sqlite\/images\/sqlite-import1.png\" alt=\"Sqlite Import 1\" \/><\/p>\n<p>To see the records:<\/p>\n<p><strong>cmd: .mode\u00a0<span class=\"keyword\">column<\/span>\u00a0\u00a0<\/strong><\/p>\n<p><strong>cmd:\u00a0<span class=\"keyword\">SELECT<\/span>\u00a0*\u00a0<span class=\"keyword\">FROM<\/span>\u00a0EMPLOYEE;\u00a0 \u00a0<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.javatpoint.com\/sqlite\/images\/sqlite-import3.png\" alt=\"Sqlite Import 3\" \/><\/p>\n<p class=\"n\">Note: .mode column is used before SELECT statement to show the data in tabular form and specifies the columns.<\/p>\n<p class=\"h1\"><strong>SQLite Export:<\/strong><\/p>\n<p>\u00a0-&gt; To export data from SQLite database to CSV file. We can export the whole table or less according to your query.<\/p>\n<p>-&gt; .once command is used to export data to a CSV file followed by the file path\/name where we want to write the file.<\/p>\n<p><strong>cmd: .header\u00a0<span class=\"keyword\">on<\/span>\u00a0\u00a0<\/strong><\/p>\n<p><strong>cmd: .mode\u00a0csv\u00a0\u00a0<\/strong><\/p>\n<p><strong>cmd: .once\u00a0\/Users\/javatpoint1\/Desktop\/sqlite\/student.csv\u00a0\u00a0<\/strong><\/p>\n<p><strong><span class=\"keyword\">cmd: SELECT<\/span>\u00a0*\u00a0<span class=\"keyword\">FROM<\/span>\u00a0STUDENT;\u00a0\u00a0<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.javatpoint.com\/sqlite\/images\/sqlite-export2.png\" alt=\"Sqlite Export 2\" \/><\/p>\n<p><strong>Code explanation:<\/strong><\/p>\n<p><strong>.header on:<\/strong>\u00a0It specifies that headers are enabled. This is optional. If you disable headers, the CSV file simply won&#8217;t contain any data.<\/p>\n<p><strong>.mode csv:<\/strong>\u00a0It specifies that CSV mode is enabled.<\/p>\n<p><strong>.once:<\/strong>\u00a0It specifies that the output to be written to the CSV file and next is the exact location.<\/p>\n<p>After execution of the above code, a CSV file is created on the specified location.<\/p>\n<p>-&gt; To open the csv file automatically<\/p>\n<p><strong>cmd: .system\u00a0\/Users\/javatpoint1\/Desktop\/sqlite\/student.csv\u00a0\u00a0<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&#8211;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>-&gt; SQLite is an open source, zero-configuration, self-contained, stand alone, transaction relational database engine designed to be embedded into an application. -&gt;\u00a0SQLite does not have a separate server process. It&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_eb_attr":""},"categories":[1],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v19.10 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>SQLite - Blink SQL<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blinksql.com\/?p=227\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQLite - Blink SQL\" \/>\n<meta property=\"og:description\" content=\"-&gt; SQLite is an open source, zero-configuration, self-contained, stand alone, transaction relational database engine designed to be embedded into an application. -&gt;\u00a0SQLite does not have a separate server process. It&hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blinksql.com\/?p=227\" \/>\n<meta property=\"og:site_name\" content=\"Blink SQL\" \/>\n<meta property=\"article:published_time\" content=\"2017-12-10T11:57:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javatpoint.com\/sqlite\/images\/sqlite-import1.png\" \/>\n<meta name=\"author\" content=\"Hannie\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@harika_sanaka\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Hannie\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/blinksql.com\/?p=227#article\",\"isPartOf\":{\"@id\":\"https:\/\/blinksql.com\/?p=227\"},\"author\":{\"name\":\"Hannie\",\"@id\":\"https:\/\/blinksql.com\/#\/schema\/person\/f04b99304f59e14956e768e764d2afd4\"},\"headline\":\"SQLite\",\"datePublished\":\"2017-12-10T11:57:34+00:00\",\"dateModified\":\"2017-12-10T11:57:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/blinksql.com\/?p=227\"},\"wordCount\":504,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/blinksql.com\/#organization\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/blinksql.com\/?p=227#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/blinksql.com\/?p=227\",\"url\":\"https:\/\/blinksql.com\/?p=227\",\"name\":\"SQLite - Blink SQL\",\"isPartOf\":{\"@id\":\"https:\/\/blinksql.com\/#website\"},\"datePublished\":\"2017-12-10T11:57:34+00:00\",\"dateModified\":\"2017-12-10T11:57:34+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/blinksql.com\/?p=227#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/blinksql.com\/?p=227\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/blinksql.com\/?p=227#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/blinksql.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQLite\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/blinksql.com\/#website\",\"url\":\"https:\/\/blinksql.com\/\",\"name\":\"Blink SQL\",\"description\":\" Thinking SQL\",\"publisher\":{\"@id\":\"https:\/\/blinksql.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/blinksql.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/blinksql.com\/#organization\",\"name\":\"Blink SQL\",\"url\":\"https:\/\/blinksql.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/blinksql.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/blinksql.com\/wp-content\/uploads\/2022\/11\/cropped-BlinkSQL-removebg.png\",\"contentUrl\":\"https:\/\/blinksql.com\/wp-content\/uploads\/2022\/11\/cropped-BlinkSQL-removebg.png\",\"width\":280,\"height\":172,\"caption\":\"Blink SQL\"},\"image\":{\"@id\":\"https:\/\/blinksql.com\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/blinksql.com\/#\/schema\/person\/f04b99304f59e14956e768e764d2afd4\",\"name\":\"Hannie\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/blinksql.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c5876b3497d2c2eb98256b7c183220c1?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c5876b3497d2c2eb98256b7c183220c1?s=96&d=mm&r=g\",\"caption\":\"Hannie\"},\"sameAs\":[\"http:\/\/blinksql.com\",\"https:\/\/twitter.com\/harika_sanaka\"],\"url\":\"https:\/\/blinksql.com\/?author=2\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SQLite - Blink SQL","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blinksql.com\/?p=227","og_locale":"en_US","og_type":"article","og_title":"SQLite - Blink SQL","og_description":"-&gt; SQLite is an open source, zero-configuration, self-contained, stand alone, transaction relational database engine designed to be embedded into an application. -&gt;\u00a0SQLite does not have a separate server process. It&hellip;","og_url":"https:\/\/blinksql.com\/?p=227","og_site_name":"Blink SQL","article_published_time":"2017-12-10T11:57:34+00:00","og_image":[{"url":"https:\/\/www.javatpoint.com\/sqlite\/images\/sqlite-import1.png"}],"author":"Hannie","twitter_card":"summary_large_image","twitter_creator":"@harika_sanaka","twitter_misc":{"Written by":"Hannie","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/blinksql.com\/?p=227#article","isPartOf":{"@id":"https:\/\/blinksql.com\/?p=227"},"author":{"name":"Hannie","@id":"https:\/\/blinksql.com\/#\/schema\/person\/f04b99304f59e14956e768e764d2afd4"},"headline":"SQLite","datePublished":"2017-12-10T11:57:34+00:00","dateModified":"2017-12-10T11:57:34+00:00","mainEntityOfPage":{"@id":"https:\/\/blinksql.com\/?p=227"},"wordCount":504,"commentCount":0,"publisher":{"@id":"https:\/\/blinksql.com\/#organization"},"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/blinksql.com\/?p=227#respond"]}]},{"@type":"WebPage","@id":"https:\/\/blinksql.com\/?p=227","url":"https:\/\/blinksql.com\/?p=227","name":"SQLite - Blink SQL","isPartOf":{"@id":"https:\/\/blinksql.com\/#website"},"datePublished":"2017-12-10T11:57:34+00:00","dateModified":"2017-12-10T11:57:34+00:00","breadcrumb":{"@id":"https:\/\/blinksql.com\/?p=227#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blinksql.com\/?p=227"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/blinksql.com\/?p=227#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blinksql.com\/"},{"@type":"ListItem","position":2,"name":"SQLite"}]},{"@type":"WebSite","@id":"https:\/\/blinksql.com\/#website","url":"https:\/\/blinksql.com\/","name":"Blink SQL","description":" Thinking SQL","publisher":{"@id":"https:\/\/blinksql.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blinksql.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/blinksql.com\/#organization","name":"Blink SQL","url":"https:\/\/blinksql.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blinksql.com\/#\/schema\/logo\/image\/","url":"https:\/\/blinksql.com\/wp-content\/uploads\/2022\/11\/cropped-BlinkSQL-removebg.png","contentUrl":"https:\/\/blinksql.com\/wp-content\/uploads\/2022\/11\/cropped-BlinkSQL-removebg.png","width":280,"height":172,"caption":"Blink SQL"},"image":{"@id":"https:\/\/blinksql.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/blinksql.com\/#\/schema\/person\/f04b99304f59e14956e768e764d2afd4","name":"Hannie","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blinksql.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c5876b3497d2c2eb98256b7c183220c1?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c5876b3497d2c2eb98256b7c183220c1?s=96&d=mm&r=g","caption":"Hannie"},"sameAs":["http:\/\/blinksql.com","https:\/\/twitter.com\/harika_sanaka"],"url":"https:\/\/blinksql.com\/?author=2"}]}},"_links":{"self":[{"href":"https:\/\/blinksql.com\/index.php?rest_route=\/wp\/v2\/posts\/227"}],"collection":[{"href":"https:\/\/blinksql.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blinksql.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blinksql.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blinksql.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=227"}],"version-history":[{"count":0,"href":"https:\/\/blinksql.com\/index.php?rest_route=\/wp\/v2\/posts\/227\/revisions"}],"wp:attachment":[{"href":"https:\/\/blinksql.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=227"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blinksql.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=227"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blinksql.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=227"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}