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

    针对库的相关操作 

      增
      create database 库名称
      删
      drop database 库名称
      改
      alter database 库名称 要改的属性名称
      alter database db1 DEFAULT CHARACTER SET utf8;
      alter database db1 CHARSET utf8;
      注意 在mysql中 utf-8 不能带- 写成utf8
      查
      show databases查看所有数据库
      show create databases 库名称 查看建库的语句

    命名规范:

      1.不能使用纯数字
      2.可以是数字 字母 下滑线的组合
      3.可以下滑线开头
      4.不能是关键字 如create
      大致和python相同
      不区分 大小写

    表相关的操作


      建表时要明确数据库
      use db1;
      create table 表名称(字段名 类型(长度),....)
      create table dog(nikename char(10),gender char(1),age int)
      #创建时同时指定数据库
      create table 库名称.表名称(字段名 类型(长度),....)

      drop table 表名;


      alter table 表名称 drop|change|modify|add
      drop 字段名称
      alter table dog drop color;

      change 旧的字段名 新的字段名 新的类型
      alter table dog change gender sex char(2);

      modify 字段名 新的类型
      alter table dog modify color char(5);

      add 字段名称 类型
      alter table dog add color char(10);
    重命名表
      rename table 旧表名称 to 新表名称
      rename table dog to dogtable;

    修改表的属性
      alter table 表名 属性名 值;
      alter table dogtable DEFAULT CHARSET gbk;


      show tables;查看所有表
      desc 表名称; 查看表结构
      show create table 表名;查建表语句
      记录相关操作

      inert into 表名 values(值1,值2.....)

      delete from 表名 where 字段名称 = 值
      没有条件的话删除全部数据

      update 表名 set 字段名 = 新的值 where 字段名 = 值
      没有条件的话修改全部

      select *from 表名; *表示通配符 查看所有字段
      select 字段名称1,字段名2.. from 表名;

  • 相关阅读:
    (easy)LeetCode 223.Rectangle Area
    (easy)LeetCode 205.Reverse Linked List
    (easy)LeetCode 205.Isomorphic Strings (*)
    (easy)LeetCode 204.Count Primes
    (easy)LeetCode 203.Remove Linked List Elements
    (easy)LeetCode 202.Happy Number
    (easy)LeetCode 198.House Robber
    (easy)LeetCode 191.Number of 1 Bits
    试题分析
    使用ADO.NET访问数据库
  • 原文地址:https://www.cnblogs.com/msj513/p/9983617.html
Copyright © 2011-2022 走看看