首页 > 数据库技术 > 详细

sql的基本语法

时间:2019-04-29 18:21:53      阅读:126      评论:0      收藏:0      [点我收藏+]

一. 数据库

1.查询服务器上有哪些数据库

show databases;

2.新建数据库

create database TestSqlSugar;

3.进入数据库

use TestSqlSugar;

4.删除数据库

drop database test;

二. 数据表

1.新建表 

(1) user

create table if not exists user(
    id int auto_increment,
    userName varchar(100) not null,
    userPassword varchar(500) not null,
    age int not null,
    regTime datetime default current_timestamp,
    departmentId int,
    primary key(id)
);

(2) department

create table if not exists department
(
    id int auto_increment,
    name varchar(100) not null,
    admin varchar(100) not null,
    phone varchar(15) not null,
    primary key(id)
);

2.表查询

select * from user
select * from department
### 包含条件查询
select * from user where id in (1);
### 分页limit temp1,temp2  调过temp1条temp2条数据
select * from user limit 1,2
### 双表左关联查询,表的重命名
select user.id as Id, user.departmentId as depId, user.userName as name from user user left join department dep on(user.departmentId = dep.id)

 

sql的基本语法

原文:https://www.cnblogs.com/yxcn/p/10792057.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!