数据查询语言DQL,数据操纵语言DML,数据定义语言DDL,数据控制语言DCL。
create table student ( Sno char(5) not null unique, Sname char(20) unique, Ssex char(1), Sage int, Sdept char(15));
复制表结构和数据
create table new_dwd_inv_return_record as select * from dwd_inv_return_record;
复制表结构不复制数据
create table new_dwd_inv_return_record as select * from dwd_inv_return_record where 1 =0;
### 修改基本表
修改表名(法一):
ALTER TABLE user10 RENAME TO user11;
修改表名(法二):
RENAME TABLE user11 TO user10;
drop table <表名>
truncate table ‘表名’
ALTER TABLE dwd_pro_repay_record RENAME TO d_pro_repay_record;
select * from dwd_inv_contract where borrow_rate like '%' limit 19;
desc student;
create [unique] [cluster] index <索引名> on <表名> (<列名> [<次序][,<列名>[<次序]].....);
注:
unique:表明此索引的每个索引值只对应惟一的一个记录
cluster:表时要建立的索引是聚簇索引,即按某一列建好索引后,硬盘上的数据存储顺序也调整为按这个列的顺序存储,索引的顺序和存储顺序是一致的
drop index <索引名>;
create unique index studentIndex on student (sno);
drop index studentIndex;
create view v_payment_myisam as select * from payment;
alter table tea add id int(20) not null PRIMARY KEY ;
alter table tea drop column id;
auto_increment
alter table tab_info rename column createname to thisname;
alter table tab_info alter column thisname varchar(200) not null;
alter table tabinfo add constraint df default('嘿嘿') for thisname;
desc 表名
insert into tbl1 values('jingba',2345);
delete from tbl1 where id=1;
update tbl1 set name=""
select * from dept order by deptno limit 2,1;
select now();
select date_format(now() , '%Y-%m-%d %H:%:m:%s');
mysql>update user set authentication_string=password("123456") where user="root";
mysql> GRANT ALL PRIVILEGES ON *.* TO jiqing@"%" IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.03 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
select host,user from mysql.user;
GRANT ALL PRIVILEGES ON *.* TO 'bdr'@'%' IDENTIFIED BY 'D.123%dr' WITH GRANT OPTION;
select sum(order_price) as sunnum from orders ;
select AVG(order_price) from orders
SELECT DISTINCT (order_price) from orders;
SELECT DISTINCT(order_price) from orders ORDER BY order_price DESC;(默认,升序ASC)
SELECT DISTINCT(order_price) from orders limit 3;
SELECT customer from orders where customer LIKE 'li%'
SELECT * from orders where order_price in (300,600);
SELECT * from orders where order_price BETWEEN 300 and 600;
原文:https://www.cnblogs.com/junzifeng/p/11830794.html