Mysql基本语句

1. 在safe-updates模式下,该模式会导致非主键条件下无法执行update等

    SET SQL_SAFE_UPDATES = 0

2. 创建表

    create table common.qc_question(  
    qc_type int(10) NOT NULL,  
    qc_id int NOT NULL AUTO_INCREMENT,  
    qc_describe VARCHAR(1255) NOT NULL,  
    qc_answer VARCHAR(255) NOT NULL,  
    PRIMARY KEY ( qc_id )  
    );  

3. 查询所有数据

    select * from common.qc_question

4. 清空表的内容

    truncate table common.qc_question

5. 随即获取n组数据

    select qc_describe,qc_answer from common.qc_question where qc_type = 1 and qc_id  >=   
    (select floor( max(qc_id) * rand()) from test_qc.qc_question ) order by qc_id limit n 

6. 自增数据查询(防止查询到以前查过的数据)

    select qc_id,qc_describe, qc_answer from common.qc_question where qc_type = 1  limit 2 offset  n*2(n为请求的次数)

7. 插入数据

    insert into common.question values(qc_type,null,"qc_describe","qc_answer")

8. 指定自增的字段从某一个序号开始

    alter table qc.qc_question  AUTO_INCREMENT=55;

9. 按照指定条件删除的数据

    delete from qc.qc_question where qc_id >= 55

10 向表中添加新的字段

    alter table table1(表名) add transactor(字段名字) varchar(10) not Null

11 向表中添加索引

    alter table test.test1 add index index_test1(uid) :index_test1为索引的别名
    create index index_test2 on test.test1(trans)   : index_test2为索引的别名

12 添加主键

    Alter table tb add primary key(id);

13 获取系统当前时间:now()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值