zoukankan      html  css  js  c++  java
  • mraiadb增三删改

    MariaDB 数据类型
    MariaDB数据类型可以分为数字,日期和时间以及字符串值。
    使用数据类型的原则:够用就行, 尽量使用范围小的,而不用大的
    • 常用的数据类型
    1. 整数:int, bit
    2. 小数:decimal                        #decimal(5,2)
    3. 字符串:varchar, char                         
    4. 日期时间:date, time, datetime
    5. 枚举类型(enum)
    • 约束
    1. 主键primary key:物理上存储的顺序(主要)
    2. 非空not null:此字段不能为空(非空)
    3. 唯一unique:此字段不允许重复(独一无二)
    4. 默认default:当不填写此值时会使用默认值,如果填写则已填写为准(默认)
    5. 外键foreign key:对关系字段进行约束,当为关系字段填写值时,会到关联的表中查询此值是否存在,如果存在则填写成功,如果不存在则填写失败并抛出异常(不相关)

     

     

     sql语句-增、删、改,查
    Alter Insert into , drop delete truncate, update , select show

    --显示当前时间
    select now();
    --创建create表(id, name)
    create table zxw(
    id int primary key not null auto_increment,
    name varchar(20),
    age int
    );
    --查看表结构
    desc zhao;
    --创建students表(id, name, age, high, gender, cls_id)
    create table students (
    id int unsigned not null auto_increment primary key,
    name varchar(20),
    age tinyint unsigned default 0,
    high decimal(5,2),
    gender enum('男', '女', '中性', '保密') default '保密',
    cls_id int unsigned
    );

    MariaDB [zxw]> desc students;
    空 主键 默认值 其他
    +--------+-------------------------------------+------+-----+---------+----------------+
    | Field | Type | Null | Key | Default | Extra |
    +--------+-------------------------------------+------+-----+---------+----------------+
    | id | tinyint(3) unsigned | NO | PRI | NULL | auto_increment |
    | name | varchar(20) | YES | | NULL | |
    | age | tinyint(3) unsigned | YES | | NULL | |
    | high | decimal(5,2) | YES | | NULL | |
    | gender | enum('男','女','保密','中性') | YES | | 保密 | |
    | cls_id | tinyint(3) unsigned | YES | | NULL | |
    +--------+-------------------------------------+------+-----+---------+----------------+

    --创建classes表(id, name)
    create table classes(
    id int unsigned not null auto_increment primary key,
    name varchar(20)
    );
    --查看表的创建
    --MyISAM与InnoDB区别
    --两种类型最主要的区别就是InnDB支持事物处理与外键和行级锁
    --修改表-添加字段alter
    --alter table 表名 add 列名 类型;
    alter table students add birthday datetime;

    -- 修改表-修改字段:不重命名版
    -- alter table 表名 modify 列名 类型及约束;
    alter table students modify birthday date;

    -- 修改表-修改字段:重命名版
    -- alter table 表名 change 原名 新名 类型及约束;
    alter table students change birthday birth date;

    -- 修改表-删除字段
    -- alter table 表名 drop 列名;
    alter table students drop birthday;

    -- 删除表
    -- drop table 表名;
    drop table students;
    --增删改查
    --增加
    --全列插入0默认排序
    --insert into 表名 values(..)
    --主键字段 可以用0 null default 来站位


    -- 向students表里插入 一个学生信息
    insert into students values (0,'小明',19,188.999,'男', 1);


    --部分插入
    insert into students(id, name, age) values (0,'绿帽子',19);
    --部分插入(多条记录)
    insert into students(id, name, age) values (0,'绿帽子',19),(0,'小跳蚤',21);

    --修改
    --update 表名 set 列1=值1, 列2=值2... where 条件;
    update students set age=100 where id=1;
    update students set age=100,cls_id=77 where id=1;
    --删除
    -- 物理删除
    -- delete from 表名 where 条件
    delete from biao Truncate table biao
    delete from students where cls_id=‘88’;
    -- 逻辑删除
    -- 用一条字段来表示 这条信息是否已经不能在使用了
    -- 给students表添加一个is_delete字段 bit 类型
    alter table students add is_delete bit default 0;
    update students set is_delete=1 where id
    alter table students add is_delete bit(1);

  • 相关阅读:
    ADO.NET入门教程(五) 细说数据库连接池
    Delphi下使用指针的简单总结
    Delphi
    Delphi
    Delphi
    TXLSReadWriteII5 单元格读写
    [Delphi]Delphi开发的一些技巧
    TXLSReadWriteII2版本导出Excel文件:
    Tomcat使用startup启动,一闪而过,如何查看出错信息
    【转】Java保留固定小数位的4种方法
  • 原文地址:https://www.cnblogs.com/itzhao/p/11287201.html
Copyright © 2011-2022 走看看