zoukankan      html  css  js  c++  java
  • mysql 基本语法

    #################################################################
    #author: 陈月白
    #_blogs: http://www.cnblogs.com/chenyuebai/
    #################################################################

    version: 5.7.17

    --------------------------------------------------------------------------------------------------------------------------------------------
    
    1.数据库操作
    创建库:create database samp_db character set gbk;
    删除数据库: drop database samp_db;
    -------------------------------------------------------------------------------------------------------------------------------------------- 2.表操作
    创建表
    create table students
    (
    id int not null primary key,
    name char(12) not null,
    sex char(4) not null,
    age int not null,
    tel char(13) not null default '-'
    )
    添加列
    基本形式: alter table 表名 add 列名 列数据类型 [after 插入位置];
    示例:在表的最后追加列 address: alter table students add address char(60);
    在名为 age 的列后插入列 birthday: alter table students add birthday date after age;
    
    修改列
    基本形式: alter table 表名 change 列名称 列新名称 新数据类型;
    示例:将表 tel 列改名为 telphone: alter table students change tel telphone char(13) default "-";
    将 name 列的数据类型改为 char(16): alter table students change name name char(16) not null;
    
    删除列
    基本形式: alter table 表名 drop 列名称;
    示例:删除 birthday 列: alter table students drop birthday;
    
    重命名表
    基本形式: alter table 表名 rename 新表名;
    示例:重命名 students 表为 workmates: alter table students rename workmates;
    
    删除整张表
    基本形式: drop table 表名;
    示例: 删除 workmates 表: drop table workmates;
    
    删除整个数据库
    基本形式: drop database 数据库名;
    示例: 删除 samp_db 数据库: drop database samp_db;
    
    --------------------------------------------------------------------------------------------------------------------------------------------
    3.数据操作
    insert into students values(00001,'陈月白','male',24,'')
    INSERT into testdb.students(id,name,sex,age) VALUES (00003,'李林','male',22)
    
    delete 语句用于删除表中的数据, 基本用法为:
    delete from 表名称 where 删除条件;
    
    update 语句可用来修改表中的数据, 基本的使用形式为:
    update 表名称 set 列名称=新值 where 更新条件;
    
    select * from tablename where ...
    
    陈月白 http://www.cnblogs.com/chenyuebai
  • 相关阅读:
    C/C++中浮点数输出格式问题
    C/C++中的输出对齐设置
    C++11 中的initialize_list
    c++中的构造函数初始化列表
    C++11中的array
    STL 中的链表排序
    poj1068 Parencodings
    poj 3295 Tautology
    How To Join XLA_AE_HEADERS and RCV_TRANSACTIONS(子分类账到事务处理追溯)
    销售订单的四个主要环节和每个环节用到的常用表
  • 原文地址:https://www.cnblogs.com/chenyuebai/p/7773171.html
Copyright © 2011-2022 走看看