码迷,mamicode.com
首页 > 数据库 > 详细

sql的基本语法

时间:2019-04-29 19:09:23      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:rem   create   分页   select   code   rom   use   sql   arch   

一. 数据库

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的基本语法

标签:rem   create   分页   select   code   rom   use   sql   arch   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!