Mac comes with the sqlite3 directly in the terminal type Sqlite3 that is to enter the interactive interface of SQLite
1, create a database
The Sqlite3 command is used to create a new database such as Sqlite3 MyDB, which creates a mydb database
3.8. 10.2 - - to - - £ º: + for usage hints.sqlite>
After entering the interactive interface, how to exit, you can type. Quit to exit the interactive interface
SQLite version3.8.10.2 -- to- - -: -: +Enter ". Help" forusage Hints.sqlite>SQLite>SQLite>SQLite>. quitbogon:db lining$
2, create data table
Now that the database is created, you are ready to create the data table, and the CREATE TABLE statement is used for creating the data table
Sqlite> Create TableStudent ( ...>Idint Primary Key not NULL, ...>NameChar( -) not NULL, ...>Ageint not NULL); SQLite>
At the same time, we can use the. Tables command to see if the table was created successfully
SQLite> . tablesstudent
You can use. Schema table_name to view complete information about the table structure
SQLite> . Schema Student CREATE TABLE intprimarykeynotnullchar (20 notnull int not null); SQLite >
3. Delete Data Sheet
If we want to delete a data sheet, we can do it using the drop table_name command, as well as using it just like that. Tables to see if the table was deleted successfully
SQLite>droptable student;sqlite> . tablessqlite >
4, insert operation of data table
Inserts an item into the datasheet, using the INSERT INTO command, which is written in two ways,
One is INSERT into table_name values (,,,);
Example:
Sqlite> Insert intoStudentValues(2, "BB", A); SQLite> Select * fromstudent;1|Aa| at2|Bb| ASQLite>
One is insert into table_name (,,,) values (,,,);
Sqlite> Insert intoStudent (id,name,age) ...> Values(3, "CC", $); SQLite> Select * fromstudent;1|Aa| at2|Bb| A3|Cc| $SQLite>
5, data table selection
One of the most straightforward ways to get information from a table is select * FROM TABLE_NAME, which is given in the example above. This is not a good view,
The. Head on command turns on the output header, the. Mode column command, and formats the output columns. That's a lot more beautiful.
sqlite> select * from student ... > -- ---------------------------- 1 aa 23 2 bb 12 3 cc 45 SQLite >
At the same time, the width of the column can be set freely, or is very simple and convenient.
Sqlite>. width5,Ten, -SQLite> Select * fromstudent;id name age----- ---------- ----------1Aa at 2Bb A 3Cc $SQLite>
Basic usage of SQLite 1