- 创建语句
<code class="language-sql hljs has-numbering"><span class="hljs-operator"><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">table</span> <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> <span class="hljs-keyword">exists</span> b(id <span class="hljs-keyword">INTEGER</span> <span class="hljs-keyword">PRIMARY</span> <span class="hljs-keyword">KEY</span> AUTOINCREMENT,waijian <span class="hljs-keyword">int</span> ,<span class="hljs-keyword">FOREIGN</span> <span class="hljs-keyword">KEY</span> (waijian) <span class="hljs-keyword">REFERENCES</span> a(id)) </span></code><ul class="pre-numbering" style=""><li>1</li><li>2</li></ul><ul class="pre-numbering" style=""><li>1</li><li>2</li></ul>
上面会创建一个 b表(当次表不存在的时候)
1. id 为主键 并且自增长
2. waijian为外键来自b表的 id列作为参考
-
查询语句
-
模糊查询:
- SELECT * FROM aa WHERE name LIKE (‘王_’)
-
精准查询
- SELECT * FROM aa WHERE age >= 10 and age <12
- 分组查询
- SELECT * FROM aa GROUP BY name HAVING age >= 10
-
分页查询
- SELECT * FROM aa LIMIT 1,2
-
降序查询
- SELECT * FROM aa ORDER BY age DESC
- 升序查询(默认)
- SELECT * FROM aa ORDER BY age ASC
-
-
删除语句
- DELETE FROM aa WHERE age = 1
-
修改语句
- updata UPDATE aa set name =’去死吧’
-
插入语句
- 列全部插入
- INSERT into aa VALUES(‘王五’,12)
- 选择列部插入
- INSERT into aa (name) VALUES(‘王五’)
- 列全部插入
通配符:
* [abc]包含abc其中一个
* [1-10]1到10之间
* [a-z]a到z其中一个字符
* %一到多个字符
* _一个字符