mysql finishing - Common sql statement

First, the common sql

show variables like 'character_set_client'; # query character set

show databases; # listed in the database alter on all servers

create database if not exists test; # Creating a database

drop database fk; # delete the database

show tables from test; # display a table in the database

use test;

create table tb_dept(

    Id int primary key auto_increment, # orthopedic department number from the primary key growth

    Name varchar (18), # department name

    description varchar (100) # Description

);

show tables from test;

desc tb_dept; # View information table

show create table tb_dept;

use test;

Employees table #

create table tb_emp(

id int primary key auto_increment, # auto_increment just MySQL-specific

Name varchar(18),

sex varchar(2),

age int,

address varchar(200),

email varchar(100)

);

drop table tb_dept;

# Modify column type

# Note: Not all cases can go be modified,

# Can only be changed if the field only contains a null value.

alter table tb_emp modify sex  varchar(4);

# Add column

alter table tb_emp add tel varchar(12);

# Remove Columns

alter table tb_emp drop tel;

alter table tb_emp drop column tel;

# Column renamed

alter table tb_emp change Name emp_Name varchar(18);

# Change the name of the table

alter table tb_emp rename emp;

rename table emp to tb_emp;

# Insert | delete | Update

insert into dept_emp (Name,sex,age,address,email)values('','','','','');

delete from tb_info where tmp_name = 'zxm';

update tb_info set tmp_name = 'zrr' where id = 13;

MySql run safe-updates the mode, which will lead to the non-primary key conditions can not perform update or delete command, execute the command SET SQL_SAFE_UPDATES = 0; modify the database schema

Two, mysql the top

When the function select top achieved starting in mysql: select * from tablename limit M, N

Where M represents the (M + 1) record start, N represents the number of records returned

select * from info order by no desc limit 0,5;

Three, MySQL5.7 type in the new JSON

1, native JSON advantages are as follows:

(1) similar to the text storage, can be saved a very large data.

(2) JSON validity check : data must be inserted JSON string type job.

(3) Compared to traditional forms, through all the strings do not need to find data.

(4) Support Index: through a virtual column can be indexed on the part of the data in JSON functions.

(5) JSON makes query performance

2,  for a column is json, the need to use built-in functions json_extract ( column name , '$. Key') This function takes two parameters, the first parameter is the column name json column, the second parameter $. wherein the key is a key string json one key.

SELECT uid,json_extract(info,'$.mail') AS 'mail',json_extract(info,'$.name') AS 'name' FROM USER

Guess you like

Origin www.cnblogs.com/ivy-zheng/p/11094425.html