• MySQL数据库学习笔记--创建


    学习内容:1,代码建表格  2,表格代码导入导出 3,增删改查  4记住备份

     上午:

    重点词汇解析:

     1 create table  Nation #民族表   create是创建的意思   “#”井号用来注释 2 (
     3 code varchar(50) primary key, --primary key 设主键 
     4 name varchar(50) --varchar字符串,最后一个列名不加逗号
     5 )      
     6 ;--注意用分号结尾
    7 #家庭关系 8 create table Info 9 ( 10 code varchar(50) primary key, 11 name varchar(50) 12 ) 13 ; 14 #个人信息 15 create table presoninformition 16 ( 17 18 code varchar(50) primary key 19 Name vachar(50) 20 sex bit, 21 birthday datetime(8), 22 foreign key(Nation) inferences Nation(code),外键 23 height(6,1), 24 25 ) 26 ; 27 #工作经历 28 create table work 29 30 No. int auto_increment primary key, 31 foreign key(code) inferences personinformition(code) 32 startwork datetime(8), 33 endwork datetime(8), 34 where varchar(50), 35 bumen varchar(50), 36 ci int, 37 38 39 create table famliy 40 ( 41 id int auto_increment primary key, auto_increment 自增 42 foreign key(code) inferences personinformition(code), 43 name varchar(50), 44 infocode inferences Info(code), 45 oder int 46 47 ); 48 ;

    create table <表名>--------创建表格

    (
    <列名> <数据类型及长度(字节)> [not null],
    <列名> <数据类型及长度字节>,
    ...
    <列名> <数据类型及长度字节>
    )

    drop table <表名>删除表格

    导出数据:将sql代码转变成excel表格

    导入数据:将表格转变成sql代码;

    ****************************************备份与还原************************

    增(create),删(retrive),改(update),查(delete)  CRUD   

    添加(插入):

    insert into <表名>[(列1,列2....)] values(<'值1'>[,'值2'])
    注意:
    1.列与值要匹配(数量,类型,次序
    2.列可以省掉,但值必须与表中的总列数和列的次序完全对应。
    3.自增长列,不能省掉自增列,给自增列赋个''

    4.不要忘记单引号,数字可以不加

    例:1,insert into 表格(列1,列2,....)values('值1','值2',....)*列与值之间要一一对应*提醒标点符号一定要用英文下的  一行中插入之后没写的还显示null(虚)表示空着可能会加入内容  

     2,insert into values(‘值1’,‘值2’,....)这种情况下有几列就要写几个值;

    3,insert into value(‘’,值1,....)

    删------
    delete from car where code='c001'   *delete删除  from从哪里    一般情况式子where(当什么时候的意思)+列名 
    delete from car where brand='b001' or brand='b004'   or与//是一个意思表示逻辑关系中的或
    delete from car where brand='b001' || brand='b004'
    delete from car where brand='b007' && price>50两个条件同时满足
    delete from car where brand='b007' and price>50   &&与and标示逻辑关系中的与

    delete from 表名 where 列名='值'and/&&列名>x

    <>和  !=意思是一样的表示非


    更新
    update <表名> set <列=值>[,列=值...] where .....set后面是要改的内容   where后面是条件
    update info set sex='1' where code='p003'  
    update info set sex='0',nation='n004',birthday='1999-9-9' where code='p001'
    update car set price=price * 0.9 where price > 30
    update car set price =price * 0.95 where (brand='b006' || brand='b005')&&price>30

     例:update 表名 set 列名1='值1',....where 列名='值'

    查询
    select * from 表名
    select 列名1,列名2... from 表名 --投影
    select * from 表名 where 条件 --筛选

    1.等值与不等值
    select * from car where code='c001';
    select * from car where code != 'c001';
    select * from car where price > 30;
    --下面的都是范围
    select * from car where price >=30 && price <=50;
    select * from car where price between 30 and 50
    select * from car where brand='b002' || brand='b004' || brand='b006'
    select * from car where brand in ('b002','b004','b006')

    2.模糊查
    select * from car where name like '宝马%' %--任意多个任意字符
    select * from car where name like '%5%'
    select * from car where name like '%型'
    select * from car where name like '__5%' _ -- 一个任意字符

    3.排序
    select * from 表名 where .... order by 列名 [ASC/DESC],列名[asc/desc]....

    select * from car order by price desc
    select * from car order by brand desc,price asc

    **时刻注意每天打完代码之后一定要备份  建议适时备份,这可以那帮你很多忙记住一定要每天都备份!!

    该博文由北宋小康康(koker)于2016.05.25.晚上   发布

    别太熬夜亲

  • 相关阅读:
    rsyslog imfile 模块说明
    正确的健身是啥意思——北漂18年(79)
    CC++ 内存对齐
    异步请求和超时控制
    dubbo入门(1)
    Query Cache Configuration
    perl 批量生成分区表
    perl 通过生成mysql 批量sql
    next 跳过当前循环
    last 退出当前循环
  • 原文地址:https://www.cnblogs.com/koker/p/5527908.html
Copyright © 2020-2023  润新知