zoukankan      html  css  js  c++  java
  • MySQL常用命令(待更新)

    1、登录到mysql:
    mysql -hlocalhost -uroot -p
    2、创建数据库:
    create database;
    3、使用数据库:
    use database;
    4、创建表:
    人员:qa
    create table qa
    (
    id int not null auto_increment primary key,
    age int not null,
    name char(16) not null,
    address varchar(80),
    mobile char(11) ,
    sex char(2) not null,
    workid char(16) not null
    );
    5、设置索引:
    ALTER TABLE qa ADD INDEX index_name (workid);
    6、创建关联表
    电脑(在使用中的):computerinuse
    create table computerinuse
    (
    id int(10) not null auto_increment primary key,
    model char(18) not null,
    brand char(8) not null,
    price float(8,1) not null,
    userid char(16) not null,
    foreign key(userid) references qa(workid) on delete cascade on update cascade
    );

    7、向表中插入数据
    insert into qa values(0,24,"邵家波","济南市","13212345566","男性","00001021");
    insert into computerinuse values(0,"k870","联想",6600.67,"00001021");
    insert into qa(age,name,sex,workid) values(24,"孙甜","女性","00001025");
    8、查询表中的数据(已经从excel导入数据)

    qa表和computerinuse表


    查询地址为北京市并且性别为男性的:SELECT * FROM `qa` where address ='北京市' and sex ='男性';
    统计人数前三名的城市:SELECT address,COUNT(address) as num FROM `qa` GROUP BY address ORDER BY num DESC limit 3;
    查询不同城市的数量:SELECT count(DISTINCT address) as num FROM `qa` ;
    查询年龄大于等于20小于30的人,并按照年龄从小到大排序:SELECT * FROM `qa` WHERE age >=20 and age <30 ORDER BY age;
    查询所有姓王的人:SELECT * FROM `qa` WHERE `name` like '王%';
    8、更新表数据
    update qa set address='保定市' where name ='王新';
    update qa set sex='男性' where name ='陈羽凡';
    9、删除表中的数据
    delete from qa where address='香港';
    10、修改表
    添加列:alert table qa add position char(10);
    修改列:alter table qa change address city char(20);
    重命名表:alter table qa rename ceshi;
    删除列:alter table qa drop position;
    删除表:drop table qa;
    删除数据库:drop database zdx;

  • 相关阅读:
    Educational Codeforces Round 13 E. Another Sith Tournament 概率dp+状压
    Codeforces Round #358 (Div. 2) D. Alyona and Strings 字符串dp
    Codeforces Round #359 (Div. 2) D. Kay and Snowflake 树的重心
    Codeforces Round #311 (Div. 2) D. Vitaly and Cycle 奇环
    Codeforces Round #Pi (Div. 2) E. President and Roads 最短路+桥
    Codeforces Gym 100342J Problem J. Triatrip 三元环
    HDU 4587 TWO NODES 割点
    hdu 5615 Jam's math problem(十字相乘判定)
    C++数组作为函数参数的几个问题(转)
    UVA
  • 原文地址:https://www.cnblogs.com/Eric-zhao/p/5285788.html
Copyright © 2011-2022 走看看