SQLite concise tutorial)

Source: Internet
Author: User

Earliest use SQLite Because Sql2005 My old machine is so cool.
And, Access Not used -- Indicates that . Net .
Later Cnblogs After searching, I think SQLite Yes, because my framework itself does not use stored procedures.
Let's get down to the truth.
1 . Slave Www.sqlite.org Download SQLite 3.3.4 Version
For convenience, I decompress it. Sqlite3.exe , Put Windows Directory.
CMD Go to the command line
1)
Create Database Files :
> Sqlite3 D: "test. DB Enter
A Test. DB In D Disk.
At the same time Sqlite3 This Test. DB
2)
Use . Help See what commands are available.
>. Help Press enter.
3) You can enter SQL Statement to create a table Use ; End, and press enter to see it.
4) Check how many tables are created.
>. Tables
5) View table structure
>. Schema Table Name
6) Check the database currently on.
>. Database
7) If you want to output the query to a file
>. Output File Name
> Query statement;
The query result is output to the file. C: "query.txt

Output query results on the screen
>. Output stdout

8)Output the table structure and the index will also output
. DumpTable Name
9)Exit
>. ExitOr. Quit

2 . Slave Http://sqlite.phxsoftware.com/ Download Ado.net Driver.
Downloaded and installed, which exists in the installation directory System. Data. SQLite. dll
We only need to copy this file to the Reference Directory and add the reference SQLite Database Operation
All Ado.net All objects are SQLite For example Sqliteconnection
The connection string only needs the following method:
Data Source = D: "test. DB Or Datasource = test. DB -- Application and ApplicationProgramOr . Net Directories that can be automatically found
The rest is simple. ~~

3 . SQL Syntax
Because we used Sqlserver Or Iseries , So DDL The syntax
1) Create a single Primary Key Of Table
Create Table [admin] (
[Username] [nvarchar] (20) primary key not null,
[Password] [nvarchar] (50) not null,
[Rank] [smallint] not null,
[MailServer] [nvarchar] (50) not null,
[Mailuser] [nvarchar] (50) not null,
[Mailpassword] [nvarchar] (50) not null,
[Mail] [nvarchar] (50) not null
);
2) Create one or more Primary Key Of Table
Create Table [codedetail] (
[Cdtype] [nvarchar] (10) Not null,
[Cdcode] [nvarchar] (20) not null,
[Cdstring1] [ntext] not null,
[Cdstring2] [ntext] not null,
[Cdstring3] [ntext] not null,
Primary Key (cdtype, cdcode)

);
3) Create an index
Create index [ix_account] on [account] ([ischeck], [username]);

View and so on.
4. There are also useful SQL
Select * From sqlite_master
Select datetime ('now ')
Select date ('now ')
Select time ('now ')
For more information, see SQLite Of Wiki.

oh, someone says, it seems that when a batch of inserts is performed, starting the transaction is faster than not starting the transaction n Times
also, use parameterization as much as possible SQL, estimation and commercialization dB automatic prepare.

==============

SQLiteYou canShell/DOS commandRun the following command:

Sqlite3 film. DB "select * from film ;"

OutputHtmlTable:

Sqlite3-HTML film. DB "select * from film ;"

"Pour out" the database 」:

Sqlite3 film. DB ". Dump"> output. SQL

Use the output data to create an identical database (with the above instructions, it is standardSQLDatabase backed up ):

Sqlite3 film. DB <output. SQL

When inserting a large amount of data, you may need to run the following command first:

Begin;

After inserting the data, remember to execute this command before the data is written into the database:

Commit;

;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.