加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 数据库 > MySql > 正文

SQLITE3 TUTORIAL

发布时间:2020-05-23 08:52:27 所属栏目:MySql 来源:互联网
导读:SQLITE3 TUTORIAL

下面是脚本之家 jb51.cc 通过网络收集整理的代码片段。

脚本之家小编现在分享给大家,也给大家做个参考。

sqlite3 test.db // open sqlite and provide a database name

// Creates a table in the database
// Primary Key automatically generates values that start at 1 and increase by 1
// name is a text field that will hold employee names

create table employees (id integer primary key,name text); 

// Insert some employees

insert into employees (id,name) values(1,'Max Eisenhardt');
insert into employees (name) values('Pietro Maximoff');
insert into employees (name) values('Wanda Maximoff');
insert into employees (name) values('Mortimer Toynbee');
insert into employees (name) values('Jason Wyngarde');

// In column mode,each record is shown on a separate line with the data aligned in columns

// headers on shows the column names,if off they wouldn't show

.mode column
.headers on
select * from employees; // Show all employees

// Changes the width of the columns

.width 15 20

.exit // Closes the database

sqlite3 test.db // Reopen database

.tables // Displays the tables

// Displays every value on its own line

.mode line
select * from employees;

// Shows the statements used to create the database. You could also provide a table name to see how that single table was made

.schema OR .schema employees

// You can get a more detailed database view

.mode column
.headers on
select type,name,tbl_name,sql from sqlite_master order by type;

// Used to show the current settings

.show

// Set NULL to 'NULL'

.nullvalue 'NULL'
.show

// Change the prompt for SQLite

.prompt 'sqlite3> '
.show

// Used to export database into SQL format on the screen

.dump

// Used to output to a file

.output ./Documents/sqlite3Files/employees.sql
.dump
.output stdout // Restores output to the screen

// You don't delete a database with any command. You have to delete the file itself

// You can delete a table however

drop table employees;

// You can import the table then with

.read ./Documents/sqlite3Files/employees.sql

// .mode is used to change the formatting of the output
// OPTIONS FOR MODE : column,csv
// html: html table
// insert: insert commands used 
// list: List without commas
// tabs: Tab separated list

// How to output a CSV list to a file

.mode csv // You could define the output should be csv
.separator,// OR define the separator for the columns
.output ./Documents/sqlite3Files/employees.csv
.separator,select * from employees;
.output stdout

// Output html table

.mode html 
select * from employees;
.output stdout

// line outputs column name and value

.mode line
select * from employees;
.output stdout

// Items with double quotes

.mode tcl
select * from employees;
.output stdout

以上是脚本之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得脚本之家网站内容还不错,欢迎将脚本之家网站推荐给程序员好友。

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读