sqlite3和mysql语句_数据库sqlite3的基本语句

/*创建表格*/

/*CREATE TABLE IFNOT EXISTS t_student(id INTEGER PRIMARY KEY AUTOINCREMENT,  name TEXT, score REAL);*/

/*CREATE TABLE IFNOT EXISTS t_student(id INTEGER PRIMARY KEY AUTOINCREMENT,  name TEXT, score REAL, PRIMARY KEY (id));*/

/*CREATE TABLE IFNOT EXISTS t_student(id INTEGER PRIMARY KEY AUTOINCREMENT,  name TEXT, score REAL);*/

/*删除数据*/

/*DROP TABLE IF EXISTS t_student;*/

/*插入数据*/

/*INSERT INTO t_student(name, score) VALUES('hxj',55);

INSERT INTO t_student( score, name) VALUES('kk',55);

INSERT INTO t_student(name, score) VALUES('gf',55);

INSERT INTO t_student(name, score) VALUES('rr',55);*/

/*

INSERT INTO t_student(name, score) VALUES('huangxiao0',70);

INSERT INTO t_student(name, score) VALUES('huangxiao1',98);

*/

/*更新数据*/

/*UPDATE t_student SET name = 'MJ', score = 30;*/

/*删除数据*/

/*DELETE FROM t_student;*/

/*条件语句的使用*/

/*

UPDATE t_student SET score = 100 WHERE name = 'huangxiao0';

UPDATE t_student SET name = 'jack' WHERE score < 40;*/

/*DELETE FROM t_student WHERE score < 100;

DELETE FROM t_student ;*/

/*查询语句*/

/*查询name,属性和score属性的*/

/*SELECT name, score FROM t_student;*/

/*SELECT * FROM t_student;*/ /*查询所有的语句*/

/*SELECT * FROM t_student WHERE score < 50;*/

/*起别名*/

/*SELECT name AS myname, score AS myscore FROM t_student;*/

/*SELECT name xxname, score yyscore FROM t_student;*/

/*SELECT stu.name, stu.score FROM t_student AS stu;*/

/*SELECT stu.name, stu.score FROM t_student  stu;*/

/* *号是统配符 */

/*统计*/

/*SELECT count(*) FROM t_student WHERE score > 80;*/

/*排序*/

/*默认是升序 ASC是升序  DESC是降序 */

/*SELECT  * FROM t_student ORDER BY score;*/

/*SELECT  * FROM t_student ORDER BY score DESC;*/

/*SELECT  * FROM t_student ORDER BY score ASC;*/

/*SELECT  * FROM t_student ORDER BY score DESC , id DESC;*/

/*分页*/

/*SELECT *FROM t_student LIMIT 10,10;*/

/*SELECT *FROM t_student LIMIT 10;*/

/*简单约束*/

CREATE TABLE IFNOT EXISTS t_student(id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,  name TEXT NOT NULL, score REAL DEFAULT 2);

/*外键的使用*/

/*创建一个班级的表格*/

/*CREATE TABLE if NOT EXISTS t_class (id INTEGER PRIMARY KEY AUTOINCREMENT, nametext NOT NULL ); */

/*创建学生与班级进行关联*/

/*CREATE TABLE if NOT EXISTS t_student (id INTEGER PRIMARY KEY AUTOINCREMENT, nametext NOT NULL, age integer NOT NULL ,class_id integer NOT NULL ,CONSTRAINT

fk_student_class_id_class_id FOREIGN KEY (class_id) REFERENCES t_class(id)  );*/

/*多表查询,记得在后面在约束条件来查询,答案才正确*/

SELECT s.name, c.name FROM t_student s, t_class c WHERE s.class_id = c.id;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值