MySQL-3-操作数据库-数据表

学习SQL语句规则

3. 学习SQL语句规则

    操作文件夹
        create database db2;
        create database db2 default charset utf8; *****
        show databases;
        drop database db2;
    
    操作文件
        show tables;
        create table t1(id int,name char(10)) default charset=utf8;
        create table t1(id int,name char(10))engine=innodb default charset=utf8;
        create table t3(id int auto_increment,name char(10))engine=innodb default charset=utf8;  *****
         
        create table t1(
            列名 类型 null,
            列名 类型 not null,
            列名 类型 not null auto_increment primary key,
            id int,
            name char(10)
        )engine=innodb default charset=utf8;
            # innodb 支持事务,原子性操作
            # myisam myisam
            
            auto_increment 表示:自增
            primary key:  表示 约束(不能重复且不能为空); 加速查找
            not null: 是否为空
            数据类型:
                
                数字:
                    tinyint
                    int
                    bigint
                    
                    FLOAT
                        0.00000100000123000123001230123
                    DOUBLE
                        0.00000000000000000000100000123000123001230123
                        0.00000100000123000000000000000
                    decimal
                        0.1
                    
                字符串:
                    char(10)      速度快()
                        root      
                        root     
                    varchar(10)   节省空间
                        root
                    PS: 创建数据表定长列往前放
                    
                    text
                    
                    上传文件: 
                        文件存硬盘
                        db存路径
                时间类型
                    DATETIME
            
                enum
                set
                
                
            create table t1(
                id int signed not null auto_increment primary key,
                num decimal(10,5),
                name char(10)
            )engine=innodb default charset=utf8;
        
        清空表:
            delete from t1;
            truncate table t1;
        删除表:
            drop table t1;
        
    操作文件中内容
        插入数据:
            insert into t1(id,name) values(1,'alex');
        删除:
            delete from t1 where id<6
        修改:
            update t1 set age=18;
            update t1 set age=18 where age=17;
        查看数据:
            select * from t1;
    
    外键:
    
        create table userinfo(
            uid bigint auto_increment primary key,
            name varchar(32),
            department_id int,
            xx_id int,
            constraint fk_user_depar foreign key ("department_id",) references department('id'),
            constraint fk_xx_ff foreign key ("xx_id",) references XX('id')
        )engine=innodb default charset=utf8;
        
        create table department(
            id bigint auto_increment primary key,
            title char(15)
        )engine=innodb default charset=utf8;
        

操作文件夹

1.创建、查看、删除数据库

2.指定

操作文件

1.查看数据表

2.创建数据表

3.插入数据

 

4.插入中文编码有问题

操作文件内容

1.

2.

3.

4.

5.

6.

 

7.

 

8.

 

9.

 

10.

猜你喜欢

转载自www.cnblogs.com/c-x-m/p/9060503.html