当前位置:网站首页>Database application
Database application
2022-06-30 01:24:00 【FYHLH】
alter table Existing table name rename The new name of the table : Change database table name
alter table Table name change Name New column names data type : Change column names
alter table Table name add Name data type : Add fields
alter table Table name drop Name : Delete field
Primary key : Determine the uniqueness of the data
How to add a primary key
create table Table name (
id int
......
primary key(id)
);
create table Table name (
id int primary key,
....
)
alter table Table name add primary key(id);
The primary key increases automatically
create table Table name (
id int auto_increment;
primary key(id);
)
alter table Table name modify Primary key column name type auto_increment
Foreign keys
create table student1 (
id int ,
name varchar(20),
teacher_id int,
primary key (id)
);
create table teacher1(
id int ,
name varchar(20),
primary key (id)
);
alter table Table name add foreign key ( Foreign key column name ) references Table name pointed to ( Primary key column name );、、
conditional
where Judge the condition
and also or perhaps and The priority ratio or The height of
The statement to determine whether it is empty is is not null;
between......and......
between The number 1 and The number 2;: In numbers 1 And numbers 2 direct Include
in Specify data
Fuzzy query like
% Is to match any character
_ Match a single character If you want to query % perhaps _ When Need to add \ To escape
order by Name asc( Ascending )/desc( Descending )
limit Usually and order by Together with limit Starting value ( barring ), Number of pieces
Group keywords group by
Common functions are :
count(*) Total number of articles
max( Field name ) Maximum
min( Field name ) minimum value
avg( Field name ) Average
sum( Field name ) The sum of the
having Filter You can do it where It can't be done
having avg>70; You can filter that the average value is greater than 70 Points of
Common functions :
select version() ; Show the current MySQL Version of the software
select database(); Displays which database you are currently in
select char_length(' China '); Return the number of characters .
select length(' China '); Returns the number of bytes occupied by characters ,MySQL in , One UTF8 Coded Chinese characters account for 3 Bytes
select concat( 'a', 'b', 'c', 'd'); return 'abcd'. String concatenation function
select concat_ws( '=', 'a', 'b', 'c'); return 'a=b=c'. String concatenation function , The first is the splice spacer
select upper('abcd'); return ABCD. Converts all lowercase letters in the parameter to uppercase
select lower('ABCD'); return abcd. Converts all uppercase letters in the parameter to lowercase
select substring( ' System information class ', 1, 3 ); return System letter . The first 2 Parameters represent from 1 The first few characters , The first 3 Parameters represent the number of intercepted characters
select trim(' abc '); return abc. Used to delete all spaces around the parameter
select curdate(); Return current date
select curtime(); Return current time
select now(); Returns the current date time
select unix_timestamp(); Returns the timestamp corresponding to the current date and time ( Unit second )
select unix_timestamp('2018-05-24 20:00:00'); Returns the timestamp corresponding to the date and time specified by the parameter ( Unit second )
select from_unixtime(1527163397); Return the time stamp specified by the parameter ( Unit second ) Corresponding date and time
select datediff( '2018-05-23', now() ); Returns the number of days between the corresponding dates of the two parameters ( Subtract the second parameter from the first parameter )
select adddate( now(), -2 ); Returns the number of days before / Date and time after ( The first parameter is date time , The second parameter is the number of days , Adding back is a positive number , Subtracting forward is a negative number )
select year('2019-02-24'); return 2019 Get the year
select month('2019-02-24') return 2 Get the month
select day('2019-02-24') return 24 Acquisition date
select if( < Judge the condition >, < The return value when the condition is true >, < The return value when the condition is false > ); amount to Java The binomial operator in < Judge the condition > ? < If the condition is true, the return value > : < If the condition is false, the return value >.
Such as select if(1=1, 2, 3); return 2.
select ifnull(< Expression or field >, < The expression or field is NULL The return value of >); Usually used to give the possibility of NULL Provide default values in case of .
select ifnull(null,' John doe ') ; null You can write column names here The value of this column will be null Of Show as anonymous
select ifnull(name,' John doe ') from teacher ;
边栏推荐
- Varnish 基础概览5
- Is the numpy index the same as the image index?
- Storage engine analysis
- [Simulation Proteus] détection de port 8 bits 8 touches indépendantes
- Seata 与三大平台携手编程之夏,百万奖金等你来拿
- Varnish 基础概览7
- c语言选择,循环概述
- How did the data center change from "Britney Spears" to "Mrs. bull"?
- 【论文写作】英文论文写作指南
- “乘风破浪”的芒果超媒,能上岸吗?
猜你喜欢

Pytroch Learning Notes 6: NN network layer convolution layer

清洁、对话、带娃,扫地机摆脱“人工智障”标签

Machinery -- nx2007 (UG) finite element analysis tutorial 2 -- assembly

Interface Association of postman

R语言线性回归模型拟合诊断异常值分析家庭燃气消耗量和卡路里实例带自测题

我,33岁,字节跳动测试开发,揭开北京“测试岗”的真实收入

眼底出血术后需注意事项//每天必看

Preliminary understanding of NVIDIA Jetson nano

Transaction summary on June 25, 2022

How latex enters a matrix
随机推荐
Visual studio 2017 cannot open the include file: 'qopenglfunctions_3_3_core': no such file or directory
Quick pow: how to quickly find power
Error reporting in Luban H5 installation
post请求出现WebKitFormBoundaryk的解决办法
[recommended] how to quickly locate a bug during testing
Transaction summary on June 25, 2022
81. 搜索旋转排序数组 II
81. search rotation sort array II
c语言选择,循环概述
[535. encryption and decryption of tinyurl]
Varnish 基础概览7
[mrctf2020]ezpop-1 | PHP serialization
Using tsne to visualize the similarity of different sentences
阅读,是最廉价的高贵
Pytroch Learning Notes 6: NN network layer convolution layer
Sentinel source code analysis Part 6 - sentinel adapter module Chapter 4 zuul2 gateway
Understanding of int argc, char * * argv in C language main function
Mechanical --nx2007 (UG) -- gap analysis (interference inspection)
HC32M0+ GPIO
Vl6180x distance and light sensor hands-on experience