mysql小练习1

作者: 雅_2f4f | 来源:发表于2019-01-20 19:38 被阅读0次

SQL相关的指令:

      文件夹(数据库):

                        文件 (数据表)

                                  数据存放在文件中

      对文件夹(数据库)操作:

              1. 查看数据:

                      show databases;

                      create database db1 default charset utf8;

                      drop database db1;

                2. 使用数据库:

                      use xxx

              3. 查看数据库下的所有的表:

                      show tables;

        文件 (数据表)操作:

                创建表:

                    create table test1(

                            #列名 [列类型][auto_increment ] [not null][default]

                            id int unsigned auto_increment primary key,

                            name char(32) not null default '',

                            age int not null default 1

                    ) charset=utf8 ;

                        列类型:

                            整数型

                                  int

                                  tinyint samallint bigint

                              float: 0.00000000000145055000

                            salary decimal(5, 2):

                                                                        2000.23

                            字符串型

                                  char(32) # xxxxxxxxxx

                                    varchar(32) #

                                        效率:           

                                              char()的效率高

                                              varchar()

                                        重要场景:

                                            user pwd

                                                                                                                          MD5(pwd)=> # 32

                              时间类型

                                      datetime : 日期时间

                删除表:

                        drop table test1;

              更新表:

                        show create table xxxx;

                        desc test1;               

                        name ==> mingzi

                        alter table test1 change name mingzi varchar(32) not null default '';

                          alter table test1 drop mingzi;

                          alter table test1 add mingzi varchar(32) not null default '';

          对数据的操作:

                  查看:

                        select * from test1;

                        select id, name from test1;

                        select id, name from test1 where id=5;

                        select id, name from test1 where id<4;

                        select id, mingzi from test1 where id between 1 and 3;

                  增加数据:

                        insert into test1 (name, age) values ('xxxx', 12);

                        insert into test1 (name, age) values ('ssss', 13);

                          insert into test1 (name, age) values ('qqqq', 14);

                          insert into test1 (name, age) values ('jjjj', 15);

                          insert into test1 (name, age) values ( 'dddd', 17);

                          insert into test1 (name, age) values ('你好', 17);

                  删除数据:

                          delete * from test1 ; # 将表中的数据全部删掉

                          delete from test1 where id=1;

                            truncate test; (生产的环境下) rm -rf /*

                  更新数据:

                          update test1 set name='qqqq', age=12 where id=2

    外键:

            之前存在的问题:

                  1. 列里面的值可以随便的写, 没有的任何的约束

                    2. 维护更改的时候比较的麻烦

            改进之后:

                    1. 节省空间

                    2. 维护更改的时候比较的简单

              创建外键:

                      create table user(

                              #列名 [列类型][auto_increment ] [not null][default]

                              id int unsigned auto_increment primary key,

                              name char(32) not null default '',

                              age int not null default 1,

                              depertment_id int not null default 1,

                              constraint fk_users_depert foreign key user('depertment_id') references depertment('id'),

                              constraint fk_users_depert foreign key user('age') references couser('id')

                    ) charset=utf8 ;

                  create table depertment(

                        id int unsigned auto_increment primary key,

                        depname char(32) not null default ''

                    )charset=utf8 ;

相关文章

  • mysql小练习1

    SQL相关的指令: 文件夹(数据库): 文件 (数据表) ...

  • MySQL练习1

    -- Q1:查找最晚入职员工的所有信息 -- Q2:查找入职员工时间排名倒数第三的员工所有信息 -- Q3:查询当...

  • 外接球问题

    题型及解决办法 应用 1 2 3 4 小练习1 小练习2 小练习3 小练习4 小练习5

  • T0001函数分离参数方法

    原理 Litiの1 小练习1 小练习2 小练习3 答案 ......

  • MySQL Operation

    sql语句练习sql练习2 MYSQL导入数据出现The MySQL server is running with...

  • MySQL 数据库SQL练习

    title: MySQL 数据库SQL练习tags: MySQL,练习grammar_cjkRuby: true ...

  • 求离散型随机变量的分布列及数字特征问题

    小练习1 解析 小练习2 小练习3 解析 小练习4 解析 小练习5 解析 小练习6 解析 小练习7 解析 小练习8...

  • 分段函数求值

    概述 应用举例 1 2 3 4 5 拓展 应用举例 1 小练习1 解析 小练习2 解析 小练习3 解析 小练习4 ...

  • 数据蛙第九期就业班 2020/7/23

    MYSQL练习题 1、MySQL中的varchar和char有什么区别? 1、CHAR的长度是固定的,而VARCH...

  • mysql45答案

    mysql45 练习答案 记录一下自己对题目的理解思路还有做法-- mysql45练习数据数据表--1.学生表 S...

网友评论

    本文标题:mysql小练习1

    本文链接:https://www.haomeiwen.com/subject/bctfjqtx.html