select 别名.表字段 from 表名 别名 where 条件
sql
查询用户表中年龄大于8的用户名与年龄信息
select t.name,t.age from sys_user t where t.age>8;
查询标准年龄大于8的全部用户用户信息
select t.* from sys_user t where t.age>8;
排序order by 字段 倒序/正序(desc/asc)排序时默认是正序所有acs可以不写,排序的语句要写在查询条件后面
sql
正序
select t.* from sys_user t order by t.age;
倒序
select t.* from sys_user t order by t.age desc;
按条件查询后排序
select t.* from sys_user t where t.age>8 order by t.age;
多条件排序
select t.* from sys_user t order by t.age,t.name desc;
-
创建数据库:
CREATE DATABASE database_name;
-
删除数据库:
DROP DATABASE database_name;
-
创建表:
CREATE TABLE table_name ( column1 datatype, column2 datatype, column3 datatype, .... );
-
删除表:
DROP TABLE table_name;
-
创建索引:
CREATE INDEX index_name ON table_name (column1, column2,...);
-
删除索引:
DROP INDEX index_name;
-
创建视图:
CREATE VIEW view_name AS SELECT column1, column2,... FROM table_name WHERE condition;
-
删除视图:
DROP VIEW view_name;
-
创建存储过程:
CREATE PROCEDURE procedure_name (parameter1, parameter2,...) BEGIN SQL statements... END;
-
删除存储过程:
DROP PROCEDURE procedure_name;
-
创建触发器:
CREATE TRIGGER trigger_name BEFORE/AFTER INSERT/UPDATE/DELETE ON table_name FOR EACH ROW BEGIN SQL statements... END;
-
删除触发器:
DROP TRIGGER trigger_name;
-
创建用户:
CREATE USER 'username'@'host' IDENTIFIED BY 'password';
-
授权:
GRANT ALL PRIVILEGES ON database_name.table_name TO 'username'@'host';
-
撤销权限:
REVOKE privilege ON database_name.table_name FROM 'username'@'host';
-
设置外键约束:
ALTER TABLE table_name ADD CONSTRAINT foreign_key_name FOREIGN KEY (column1) REFERENCES parent_table (parent_column);