• mysql基础语法1


    -- cmd里启用/关闭mysql服务器,连接mysql
        -- 启用
        net start mysql
        -- 关闭
        net stop mysql
    
        -- 连接mysql
        -- -u后面是用户名,-p后面是密码
        mysql -uroot -proot
    
    -- 创建数据库
        create database if not exists db_lin;
    
    -- 查看数据库
        show database db_lin;
        show databases like 'db_%';
    
    -- 指定数据库
        use db_lin;
    
    -- 删除数据库
        drop database db_lin;
    
    -- 查询mysql中支持的存储引擎
        show engines;
    
    -- 查询默认的存储引擎
        show variables like '%storage_engine%';
    
    -- 创建表
        -- primary key 是主键,auto_increment是自动增长
        create table tb_lin(id int(5) primary key auto_increment,
                            name varchar(10) not null,
                            sex varchar(10) not null);
    
    -- 查看表结构
        desc tb_lin;
        show columns from tb_lin from db_lin;
    
    -- 重命名数据表
        rename table tb_lin to tb_lai;
    
    -- 删除数据表
        drop table tb_lin;
    
    -- 向表中添加字段
        alter table tb_lin add phone varchar(11);
    
    -- 修改表中字段类型
        alter table tb_lin modify phone varchar(15);
    
    -- 修改表中字段名
        alter table tb_lin change phone 电话 varchar(15);
    
    -- 删除主键
        alter table tb_lin drop primary key;
        -- 如果主键带有自动增长auto_increment,则需要删除自动增长,
        -- 即重新定义一下字段类型再删除
        alter table tb_lin modify id int;
        alter table tb_lin drop primary key;
    
    -- 添加主键
        alter table tb_lin add primary key(id);
    
    -- 查看表字段的所有状态
        show full columns from tb_lin;
    
    -- 修改字段编码
        alter table tb_lin modify name varchar(10) character set utf8;
    
    -- 修改表中所有字段的字符编码
        alter table tb_lin convert to character set utf8;
    
    -- 复制表
        create table tb_lin1 like tb_lin;
    
    -- 复制表及其内容
        create table tb_lin2 as select * from  tb_lin;
    
    -- delimiter 设置定界符
        delimiter //
    
    -- 创建存储过程
        delimiter //
        create procedure name()
            begin
            ......
            ......
            end
    
        -- 列:计算两个数之和,declare定义变量,default定义默认值
        create procedure pr_add (a int,b int)
            begin
            declare c int;
            if a is null then
            set a = 0;
            end if;
            if b is null then
            set b = 0;
            end if;
            set c = a + b;
            select c as sum;
            end
            //
    
        -- 调用 MySQL 存储过程
        call pr_add(10, 20);
    
    -- 插入完整的数据
        insert into tb_lin values(1,"林彬","男",17780838860);
        
    -- 插入不完整的数据
        Insert into tb_lin(id, name, sex) values(2, "林峰", "男");
        
    -- 插入查询结果
        insert into tb_lin(name, sex) select name, sex from tb_lin1;
    
    -- 修改数据
        update tb_lin set name="赖玉英", sex="女", 电话="18181592864" where id = 2;
    
    -- 删除数据
        delete from tb_lin where id=8;
  • 相关阅读:
    CEAA自动汇编脚本常用命令
    PIC之拉电流和灌电流
    CHARRANGE 结构
    汇编中的lodsb和stosb、lodsd和stosd指令
    汇编中的STOSB与STOSD指令
    汇编中的CLD指令
    SQL中distinct的用法
    SQL union介绍
    【项目排期】测试排期问题思考
    SQL join的介绍
  • 原文地址:https://www.cnblogs.com/lin961234478/p/13602676.html
Copyright © 2020-2023  润新知