zoukankan      html  css  js  c++  java
  • 数据库mysql的基本操作

    操作文件夹(数据库)

    1 增:create database db1 charset utf8;
    2 查:show databases;
    3 改:alter database db1 charset latin1;
    4 删除: drop database db1
    5 
    6 查看当前所在的数据库
    7 select database();

    操作文件(表)

    1 先切换到文件夹下:use db1
    2      增:create table t1(id int,name char);
    3      查:show tables
    4      改:alter table t1 modify name char(3);
    5          alter table t1 change name name1 char(2);
    6      删:drop table t1;
    7 
    8     查看表结构
    9     describe t1;

    修改表结构

    https://book.apeland.cn/details/460/

    表的内容操作

    1,增

    1 insert into [表名] values(1,'wu'),(2,'zhi'),(3,'bin');
    2 insert into [] (列名,列名....) values (值,值,值....),(值,值,值....);
    3 insert into [表1] (列名,列名...) select 列名,列名... from 表2; #将表1复制给表二
    1 delete from []   #清空表
    2 delete from [] where id =1 and name='wu';   #按条件删除
    1 update [] set name = 'wang' where id =1;   #按条件修改
    1 select * from []  #显示表中所有的列和数据
    2 select * from [] where id >1 ; #按条件查询
    其他
    #对条件查询
    slect * from [] where id > 5 and name != 'wuzhibin';
    slect * from [] where id between 4 and 9;
    select * from [] where id in (1,3,5);
    select * from [表1] where id in (select id from  [表2]) # 条件是表2中的ID
    1 #通配符查询
    2 select * from [] where name like 'wu%' ; #以wu开头后面可以匹配多个字符
    3 select * from [] where name like 'wu_' ; # 以wu开头后面最多匹配一个字符
    1 #查询限制
    2 select * from [] limit 5 ; #前面5行数据
    3 select * from [] limit 4,5; #从第五行开始的5行
    4 select * from [] limit 5 offset 4  # 从第武汉开始的5行
    
    1 #排序查询
    2 select * from [] order by [] asc;  #从小到大
    3 select * from [] order by [] desc;  #从大到小
    4 select * from [] order by [列1] asc[列2] desc ; 列1相等在根据列2排序
    1 #两张表组合查询
    2 select name from [表1]  union select name from [表2];  #自动去重
    3 select name from [表1] union all select name from [表2]; #不去重
    1 #连表操作
    2  select t1.id ,t1.name ,t2.name from t1,t2 where t1.nid = t2.id; 
    人生苦短,我用cnblog
  • 相关阅读:
    NanUI文档
    NanUI文档
    NanUI文档
    开源组件NanUI一周年
    NanUI文档
    NanUI 0.4.4发布
    【开源】做了一个WinForm窗体的投影组件,能够为窗口添加影子效果
    NanUI for Winform 使用示例【第二集】——做一个所见即所得的Markdown编辑器
    NanUI for Winform 使用示例【第一集】——山寨个代码编辑器
    非常简洁简单的tcp socket库 XKSocket
  • 原文地址:https://www.cnblogs.com/wuzhibinsuib/p/12656270.html
Copyright © 2011-2022 走看看