zoukankan      html  css  js  c++  java
  • 数据库Mysql 操作

    和数据库相关:
    1.创建数据库 create database db1;
    create database db1 character set gbk
    2.查看所有库: show databases;
    3.查看单独的库: show create database db1;
    4.删除数据库: drop database db1;
    5.使用数据库:use db1;
    和表相关:
    1. 创建表
    create table t1 (id int,
    name varchar(10));
    -制定引擎和字符集
    create table t1 (id int,
    name varchar(10)) engine=innodb charset=utf8;
    2.查看所有表 show tables;
    3.查看表结构 desc t1;
    4.查看表属性 show create table t1;


    对表操作
    1.创建表 create table student (id int,name varchar(10));
    2.带引擎和字符集的创建 create table student (id int,name varchar(10)) engine=innodb(myisam) charset=gbk;
    3.查看所有 show tables;
    4.查看表属性 show create table student;
    5.查看表结构 desc student;


    和表相关sql:
    1.创建表:create table t1 (id int) engine=innodb charset=utf8;
    2.查看所有: show tables;
    3.查看单个:desc t1; show create table t1;
    4.修改表名: rename table t1 to t2;
    5.添加字段: alter table t2 add age int (添加到最后面);
    alter table t2 add age int first (添加到最前面)
    alter tabke stue add age int after id;(某个字段后面添加)
    6.修改名和类型:alter table t2 change age fatherAge int;
    7.修改类型和顺序:alter table t2 modify fatherAge varchar(20) (first或after 字段名);
    8.修改属性:alter table t2 engine=myisam charset=utf8;
    8.删除字段:alter table t2 drop age;
    9.删除表: drop table t2;

    数据相关SQL
    1.插入数据:
    insert into t1 values(2,'lisi',2,3);
    insert into t1 values(3,'wangwu',2,3);
    insert into t1 values(4,'zhaoliu',2,3);


    insert into student (id,name) values (1,'xm');
    批量就是在values后面写多个小括号 通过, 分开 括号里面写值
    2.查询数据:select * from student;
    select id,name from student;
    3.修改数据: update student set age=18 where age=20;
    4.删除:delete from student where age=18;

    查看

    select title from t_item;

    select title from where category='riyongping';

    更多数据库知识点个关注哦,一起交流

  • 相关阅读:
    Google笔试题
    OpenStack Ceilometer简介
    OpenStack Object Storage(Swift)架构、原理及特性
    【大话存储2读书笔记】磁盘IO的重要概念
    递归,汉诺塔游戏
    函数定义与使用
    字符串操作
    for循环:用turtle画一颗五角星
    列表、元组、字典、集合的定义、操作与综合练习
    npm 相关
  • 原文地址:https://www.cnblogs.com/xyk1987/p/8472189.html
Copyright © 2011-2022 走看看