zoukankan      html  css  js  c++  java
  • 表 库 数据 分页 if while 操作

     1 -- 创建数据库
     2 create database mysql_L1 default character
     3 set utf8 -- 默认编码
     4 collate utf8_general_ci -- 排序规则
     5 
     6 -- 使用数据库
     7 use mysql_L1;
     8 -- 获取当前数据库登录账号
     9 select user() 
    10 -- 获取当前使用的数据库
    11 select database();
    12 
    13 
    14 -- 创建表
    15 create table student(
    16         sid int primary key auto_increment, -- 标识列 默认从 1 开始
    17         sname varchar(20), -- 姓名
    18         sex varchar(2), -- 性别
    19         birth int -- 年龄
    20 )auto_increment = 1001;   -- 给的默认值从 1001 开始 
    21 
    22 
    23 -- 查看建表结构
    24 show columns from student
    25 -- 删除表
    26 drop table student -- 可能会报错(如果表不存在就会报错)
    27 drop table if exists student -- 不会报错
    28 
    29 -- 向 student 表中添加单行数据
    30 insert into student (sname,sex,birth) values('张三','','21');  -- 单行数据添加
    31 -- 向 student 表中添加多行数据
    32 insert into student (sname,sex,birth)values  -- 多行数据添加
    33 ('张三','','22'),
    34 ('张三','','22'),
    35 ('张三','','22'),
    36 ('张三','','22'),
    37 ('张三','','22'),
    38 ('张三','','22'),
    39 ('张三','','22');
    40 
    41 
    42 -- 分页查询
    43 select * from student limit 5,5;  -- limit 5,5 是去掉前五条数据显示五条数据
    44  
    45 -- mysql 中的 if
    46 
    47 if 条件 then
    48             语句块
    49 end if;
    50 -- 带 else 的 if
    51 if 条件1 then
    52         语句块1
    53         else if 条件2 then
    54         语句块2
    55         else 
    56         语句块3
    57 end if;
    58 
    59 -- mysql 中的 whiile 循环  (repeat loop) 这两个也是循环
    60 while 条件 do
    61             循环体
    62 end while;
    63 
    64 
    65 
    66 
    67 select * from student;
  • 相关阅读:
    递归算法
    C#委托
    final 、finally
    JSP中的日期问题
    为GirdView添加CSS样式
    PC连Moto V180上网
    CSS条状图表:垂直型
    树型列表的实现
    关闭窗口无提示
    用PhotoShop做漂亮的相框,哈哈
  • 原文地址:https://www.cnblogs.com/Lvhengshuai/p/6817177.html
Copyright © 2011-2022 走看看