zoukankan      html  css  js  c++  java
  • mysql数据库

    use book -- 选择使用的数据库
    create table publisher(
    id int not null primary key auto_increment ,
    name varchar(40) not null ,
    shortname varchar(20) not null ,
    code VARCHAR(10) not null ,
    remark varchar(100)
    )
    -- not null 字段不允许为空
    -- primary key 主键
    -- auto_increment 自动增长 一般id为自动增长
    -- unique 唯一性
    -- default 'xxxx' 给字段设置默认值
    -- show databases 查看所有的数据库
    -- show TABLES 查看所有表
    -- select * from publisher 查询publisher表里面所有的数据
    -- select * from publisher where code='bjschool' 指定条件
    -- select id,name,shortname from publisher 指定查询字段
    -- select * from supplier where name ='供货商01' and contact_person='小王' and当条件同时满足的时候才查询出来
    -- select * from supplier where name ='供货商01' or contact_person='小王' or两个条件满足期中一个就可以查询导数据
    -- select * from blk where money BETWEEN 1000 and 10000;在什么什么之间的数据
    -- select * from blk ORDER BY money desc; ORDER BY 排序的含义,desc是降序,asc升序
    -- select * from blk where stu_name in ('阿翔','林倩','米远');# in包含
    -- select *from blk where name like '%米%' like模糊查询,%匹配任意一个字符

    -- 建表语句解析如下
    -- 创建一个supplier表
    create table supplier(
    -- id字段,数据类型是int,主键,不允许为空,自动增长,具有唯一性
    id int not null primary key auto_increment UNIQUE,
    -- name字段,数据类型是varchar(可变长度字符),不允许为空,备注为供货商单位名称
    name varchar(15) not null COMMENT'供货商单位名称',
    -- contact_person ,数据类型是varchar,不允许为空,备注是联系人
    contact_person varchar(25) not null COMMENT'联系人',
    -- tel,数据类型是varchar,不允许为空,备注为联系电话
    tel varchar(11) not null COMMENT'联系电话',
    -- statusid,数据类型是int ,不允许为空,外键,与status表的id有关联,备注为状态
    statusid int not null COMMENT'状态',
    -- code,数据类型是varchar not null ,备注是编码
    code varchar(10) not null COMMENT'编码'
    )
    insert into supplier(name,contact_person,tel,statusid,code) VALUES('供货商01','张三','111111111',1,'s01'),
    ('供货商02','李四','222222',2,'s02'),('供货商03','王五','3333',1,'s03'),('供货商04','赵六','44444',1,'s04'),
    ('供货商07','齐齐','7777',1,'s07')
    insert into supplier(name,contact_person,tel,statusid,code) VALUES('供货商01','小王','111111111',1,'s01')


    create table status(
    id int PRIMARY KEY auto_increment not null UNIQUE,
    name varchar(10) not null
    )
    create table supplierroll(
    id int PRIMARY key not null unique,
    -- 供货商账号
    snum varchar(50) not null,
    -- 供货商id,与supplier有关联,外键
    sid int not null ,
    -- 状态,与status有关联外键
    statusid int not null
    )
    -- 修改表字段的属性,增加id字段的唯一性的属性,唯一性的含义是id在表中的值是唯一的
    alter table publisher add unique(id)
    -- 批量插入语句
    insert into publisher(name,shortname,code) VALUES('清华大学出版社','清华出版','qhschool'),('北京大学出版社','北大出版','bjschool')
    -- 单一的插入语句
    insert into publisher(name,shortname,code) VALUES('北京邮电大学出版','北邮出版','byschool')
    insert into publisher(name,shortname,code) VALUES('北京邮电大学出版','北邮出版','byschool')
    INSERT into status (name) VALUES('可用'),('不可用')
    -- 删除blk表中所有的数据
    delete from blk
    -- 根据条件删除表中的数据
    delete from blk where money=10
    -- 根据条件更新表中的数据
    update publisher set remark='知名出版社' where code='qhschool'

  • 相关阅读:
    asp.net微信内置浏览器下Session失效
    iOS 开发之路(WKWebView内嵌HTML5之图片上传) 五
    移动Web开发(二)
    iOS 开发之路(使用WKWebView加载Html5) 四
    iOS 开发之路(AES/DES加密实现) 三
    移动Web开发(一)
    iOS 开发之路(登陆验证调用WebService)二
    iOS 开发之路(登陆页键盘遮挡输入框问题)一
    canvas绘画常用方法
    JavaScript函数定义方式
  • 原文地址:https://www.cnblogs.com/msmx/p/10086586.html
Copyright © 2011-2022 走看看