Home Database Mysql Tutorial sqlite基本sql语句使用

sqlite基本sql语句使用

Jun 07, 2016 pm 02:58 PM
sql sqlite use Basic statement

sqlite基本sql语句使用 一,SQLite常见的数据类型 SQLite是无类型的。 这意味着你可以保存任何类型的数据到你所想要保存的任何表的任何列中,无论这列声明的数据类型是什么(只有自动递增Integer Primary Key才有用)。对于SQLite来说对字段不指定类型是完全有

sqlite基本sql语句使用

 

一,SQLite常见的数据类型

SQLite是无类型的。 这意味着你可以保存任何类型的数据到你所想要保存的任何表的任何列中,无论这列声明的数据类型是什么(只有自动递增Integer Primary Key才有用)。对于SQLite来说对字段不指定类型是完全有效的。 即使SQLite允许忽略数据类型,但是仍然建议在你的Create Table语句中指定数据类型。 因为数据类型对于你和其他的程序员交

流,或者你准备换掉你的数据库引擎是非常有用的。SQLite只支持常见的5种存储类,

   NULL

   INTEGER  --整型

   REAL      --浮点数

   TEXT      --文本

   BLOB      --大二进制对象

以下定义的数据类型都会转到相应的存储类中。

create  table  tab(            --注意其中的注释方式 

  a  VARCHAR(10),          --长度不固定且其最大长度为n的字符串

  b  NVARCHAR(15),

c  TEXT,                  --二进制对象

d  INTEGER,              --带符号的整型,具体取决于存入数字的范围大小

e  FLOAT,            

f  BOOLEAN,   

g  CLOB,                 --使用CHAR来保存数据

      h  BLOB,                 --使用二进制对象保存数据,如保存位图

      i  TIMESTAMP,

      j  NUMBERIC(10,5),

      k  VARYING CHARACTER(24),

      l  NATIONAL VARYING CHARACTER(16),    //

      j  REAL                  --浮点数字,存储为8-byte IEEE浮点数

);

二,        基本的数据操作

1,建立表

Create  table  admin(

username text,

age integer);

2,插入数据

    insert into 表名(字段列表) values(值列表);

    例如:insert  into admin values(‘song’,25);

3,查询

    select 字段名 from 表名;

    select * from admin;

    select  distinct  field  from  table_name;(distinct去掉重复项,将列中各字段值单个列出)

    

4,删除数据

    Delete from 表名 where 条件子句。

    delete from admin form where username=’song’;

5,修改

    update 表名 set 字段名=值 where 条件子句。

    update admin set username=’zhang’,age=24 where username=’song’ and age=25;

6,按条件分组

   select * from 表名 where 条件子句 group by 分组子句 having …order by排子句

    例如:

       select * from admin;

       select * from admin order by id desc(降序) | asc(升序);

       select username from admin group by username having count(*)>1;

7,多条件查询语句

    select 字段名 from 表名 where  子句1 按 子句二

    select * from admin where username=’song’ and age=24;

    select * from table_name where field in (‘val1’ , ’val2’ , ‘val3’ );

    select * from table_name where field between  val1 and val2;

    select * from admin limit 5;        --限制输出数据记录数量

8,多条件排序

   select 字段名 from 表名 order by 字段1 (desc),字段2(desc);

   select * from admin order by t1 ,t2 desc;

9,索引

    例如 建立复合索引:create index  idxT1  on admin(username,age);

         各自建立索引:create index  idxUsername on  admin(username);

                       create index  idxAge on admin(age);

10,外键FOREIGN KEY(UNIQUE | PRIMARY KEY | NOT NULL)的用法()

     create table a(

a1 INTEGER  PRIMARY KEY | UNIQUE | NOT NULL,

a2 TEXT,

a3 INTEGER );

     create table b()(

b1 INTEGER ,

b2 TEXT,

b3 INTEGER,

foreign key(b3) references a(a1));

11,分页

     select * from account limit 5 offset 3; 

     或者  select * from account limit 5,3;

12,模糊查询

      SELECT 字段 FROM 表 WHERE 某字段 LIKE 条件

     (1)%:表示任意0个或多个字符

     (2)_ :表示任意单个字符,匹配单个任意字符,常用来限制表达式的字符长度语句。

     (3)[ ]:表示括号内所列字符中的一个(类似正则表达式)

           select * from admin where username like ‘[张李王]三’;

           表示搜索的是“张三”,“李三”或“王三”

       [4]:[^]表示不在括号所列之类的单个字符。

       [5]:查询内容包含通配符时,用“[ ]”括起来。

13,删除表 | 索引

     drop table [ IF EXISTS] admin;

     drop index index_name

14,查询记录数目

     select count(*) from table_name;

 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the difference between HQL and SQL in Hibernate framework? What is the difference between HQL and SQL in Hibernate framework? Apr 17, 2024 pm 02:57 PM

HQL and SQL are compared in the Hibernate framework: HQL (1. Object-oriented syntax, 2. Database-independent queries, 3. Type safety), while SQL directly operates the database (1. Database-independent standards, 2. Complex executable queries and data manipulation).

What software is crystaldiskmark? -How to use crystaldiskmark? What software is crystaldiskmark? -How to use crystaldiskmark? Mar 18, 2024 pm 02:58 PM

CrystalDiskMark is a small HDD benchmark tool for hard drives that quickly measures sequential and random read/write speeds. Next, let the editor introduce CrystalDiskMark to you and how to use crystaldiskmark~ 1. Introduction to CrystalDiskMark CrystalDiskMark is a widely used disk performance testing tool used to evaluate the read and write speed and performance of mechanical hard drives and solid-state drives (SSD). Random I/O performance. It is a free Windows application and provides a user-friendly interface and various test modes to evaluate different aspects of hard drive performance and is widely used in hardware reviews

Usage of division operation in Oracle SQL Usage of division operation in Oracle SQL Mar 10, 2024 pm 03:06 PM

"Usage of Division Operation in OracleSQL" In OracleSQL, division operation is one of the common mathematical operations. During data query and processing, division operations can help us calculate the ratio between fields or derive the logical relationship between specific values. This article will introduce the usage of division operation in OracleSQL and provide specific code examples. 1. Two ways of division operations in OracleSQL In OracleSQL, division operations can be performed in two different ways.

How to download foobar2000? -How to use foobar2000 How to download foobar2000? -How to use foobar2000 Mar 18, 2024 am 10:58 AM

foobar2000 is a software that can listen to music resources at any time. It brings you all kinds of music with lossless sound quality. The enhanced version of the music player allows you to get a more comprehensive and comfortable music experience. Its design concept is to play the advanced audio on the computer The device is transplanted to mobile phones to provide a more convenient and efficient music playback experience. The interface design is simple, clear and easy to use. It adopts a minimalist design style without too many decorations and cumbersome operations to get started quickly. It also supports a variety of skins and Theme, personalize settings according to your own preferences, and create an exclusive music player that supports the playback of multiple audio formats. It also supports the audio gain function to adjust the volume according to your own hearing conditions to avoid hearing damage caused by excessive volume. Next, let me help you

Comparison and differences of SQL syntax between Oracle and DB2 Comparison and differences of SQL syntax between Oracle and DB2 Mar 11, 2024 pm 12:09 PM

Oracle and DB2 are two commonly used relational database management systems, each of which has its own unique SQL syntax and characteristics. This article will compare and differ between the SQL syntax of Oracle and DB2, and provide specific code examples. Database connection In Oracle, use the following statement to connect to the database: CONNECTusername/password@database. In DB2, the statement to connect to the database is as follows: CONNECTTOdataba

How to use Baidu Netdisk app How to use Baidu Netdisk app Mar 27, 2024 pm 06:46 PM

Cloud storage has become an indispensable part of our daily life and work nowadays. As one of the leading cloud storage services in China, Baidu Netdisk has won the favor of a large number of users with its powerful storage functions, efficient transmission speed and convenient operation experience. And whether you want to back up important files, share information, watch videos online, or listen to music, Baidu Cloud Disk can meet your needs. However, many users may not understand the specific use method of Baidu Netdisk app, so this tutorial will introduce in detail how to use Baidu Netdisk app. Users who are still confused can follow this article to learn more. ! How to use Baidu Cloud Network Disk: 1. Installation First, when downloading and installing Baidu Cloud software, please select the custom installation option.

Detailed explanation of the Set tag function in MyBatis dynamic SQL tags Detailed explanation of the Set tag function in MyBatis dynamic SQL tags Feb 26, 2024 pm 07:48 PM

Interpretation of MyBatis dynamic SQL tags: Detailed explanation of Set tag usage MyBatis is an excellent persistence layer framework. It provides a wealth of dynamic SQL tags and can flexibly construct database operation statements. Among them, the Set tag is used to generate the SET clause in the UPDATE statement, which is very commonly used in update operations. This article will explain in detail the usage of the Set tag in MyBatis and demonstrate its functionality through specific code examples. What is Set tag Set tag is used in MyBati

How to use Xiaoai Speaker How to connect Xiaoai Speaker to mobile phone How to use Xiaoai Speaker How to connect Xiaoai Speaker to mobile phone Feb 22, 2024 pm 05:19 PM

After long pressing the play button of the speaker, connect to wifi in the software and you can use it. Tutorial Applicable Model: Xiaomi 12 System: EMUI11.0 Version: Xiaoai Classmate 2.4.21 Analysis 1 First find the play button of the speaker, and press and hold to enter the network distribution mode. 2 Log in to your Xiaomi account in the Xiaoai Speaker software on your phone and click to add a new Xiaoai Speaker. 3. After entering the name and password of the wifi, you can call Xiao Ai to use it. Supplement: What functions does Xiaoai Speaker have? 1 Xiaoai Speaker has system functions, social functions, entertainment functions, knowledge functions, life functions, smart home, and training plans. Summary/Notes: The Xiao Ai App must be installed on your mobile phone in advance for easy connection and use.

See all articles