当前位置:Gxlcms > 数据库问题 > mysql

mysql

时间:2021-07-01 10:21:17 帮助过:15人阅读

数据类型分为:数、小数、字符串、时间日期

    数:TINYINT 1字节 -128~127、 SMALLINT 2字节 -32768~32767
           INT     4字节  +- 21亿、BIGINT   8字节 
    小数:FLOAT 、DOUBLE 、DECIMAL(m,n) 精确到小数点后的位数
           (m,n) m表示这个数字的位数,n表示,小数点之后有几位
    字符串:
           CHAR(m)  --m表示该字段可以表述的字符串的长度,最多为255
           VARCHAR(m) --m表示该字段可以表述的长度
           BLOB --用于存储二进制大文件
    时间日期:DATE --表示日期 1000-1-1 ~ 9999-12-31
           TIME --表示时间 00:00:00 ~ 23:59:59
           datetime --1000-1-1 00:00:00 ~9999-12-31 23:59:59


    not null:非空约束,指定某列不为空
    unique: 唯一约束,指定某列和几列组合的数据不能重复
    primary key:主键约束,指定某列的数据不能重复、唯一
    foreign key:外键,指定该列记录属于主表中的一条记录,参照另一条数据
    check:检查,指定一个表达式,用于检验指定数据


Not null(非空)

     create table temp(        
     id int not null, 

    (id--字段   int--数据类型  not null--非空约束)        
     name varchar(255) not null default ‘abc’,   

   (name原是非空约束,但是若没有输入则默认为abc)     
     sex char null
      );


Unique(唯一)

     create table temp (        
        id int not null,        
        name varchar(25),   (也可以在逗号前面直接输入 unique)        
        password varchar(16),
        constraint uk_name_pwd unique(name, password)
        );

    添加唯一约束 :alter table temp add unique(name, password);
    修改唯一性约束:alter table temp modify name varchar(25) unique; 
    删除约束 :alter table temp drop index name;

Primary key(主键)

    id int primary key
    constraint pk_temp_id primary key(id)
    alter删除主键约束 :alter table temp drop primary key;  
    alter添加主键 :alter table temp add primary key(name, pwd);   
    alter修改列为主键 :alter table temp modify id int primary key;

          设置主键自增:auto_increment
          id int auto_increment primary key,   

insert into 表名(列名1,列名2,列名3,......)values(列名1值,列名2值,列名3值,......);

intsert into 表名values(列名1值,列名2值,列名3值,......);

删除

Delete from 表名;   删除是全部内容

Delete from stu;

查询

Select * from 表名;  查询表的全部内容

Select * from stu;

 

(例子写完再放)

mysql

标签:大型数据库   计算机硬件   数据库技术   计算机应用   信息技术   

人气教程排行