zoukankan      html  css  js  c++  java
  • 常用的SQL语句

    常用的SQL语句,包括建表语句,增删改查,如以下为实现创建表user,内容包括id,用户名,密码,年龄,性别,联系-- 建表语CREATE table user(

    id int primary key not NULL auto_increment,
    username varchar(20) not null,
    password varchar(20) not null,
    age int not null,
    sex varchar(20) not null,
    phoneNum varchar(15) not null

    )
    --查询数据
    1、查询所有数据
    select * from user;
    2、按照id查找数据
    select * from user where id=?;
    3、查询所有数据,按照用户名排序
    select * from user order by username;
    4、查询两表关联

    左连接left jion 关键字会从左表哪里返回所有的行,即使右表中没有匹配的行
    select * from user left join address on user.id = address.id ;
    右连接right jion 关键字会从右表哪里返回所有的行,即使左表中没有匹配的行
    select * from user right join address on user.id = address.id ;
    全连接full jion 只要其中某个表存在匹配,就会返回所在的行
    select * from user full join address on user.id = address.id ;

    --插入语句
    表中id为自增,所以无需添加
    insert into user values('xijin-wu','123',18,'男','1568791315');

    insert into user(username,password,age,sex,phoneNum) valuses('xijin-wu','123',18,'男','1568791315');
    --更新语句
    update user set password ='456' where id=1;

    --删除语句
    delete from user where id=1;
    
    
  • 相关阅读:
    自定义、操作cookie
    云中沙箱学习笔记2-ECS之初体验
    云中沙箱学习笔记1-快速部署并使用MySQL数据库
    练习小程序
    理解Thread.sleep()函数
    排序:冒泡排序;直接选择排序;反转排序
    float和double
    BigDecimal
    Linux学习笔记5(2)-CentOS7中Tomcat8修改jvm内存配置
    ret2dl学习笔记
  • 原文地址:https://www.cnblogs.com/xijin-wu/p/5292552.html
Copyright © 2011-2022 走看看