当前位置:网站首页>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 ;
边栏推荐
- [Thesis Writing] English thesis writing guide
- Mysql 监控1
- Equivalence class partition method for test case design method
- Sfdp 超级表单开发平台 V6.0.4 正式发布
- MES管理系统功能模块之质量管理
- Solving plane stress problem with MATLAB
- Cantilever beam calculation [matlab code]
- Clean, talk, bring children, and get rid of the label of "artificial mental retardation" for the sweeper
- Varnish 基础概览3
- What is digital garbage? Follow the world's first AI artist to explore meta carbon Art
猜你喜欢

How to seamlessly transition from traditional microservice framework to service grid ASM

Seata and the three platforms are working together in the summer of programming. Millions of bonuses are waiting for you

Clean, talk, bring children, and get rid of the label of "artificial mental retardation" for the sweeper
![[535. encryption and decryption of tinyurl]](/img/b7/7748febe30852ca428fe86b045e9ca.png)
[535. encryption and decryption of tinyurl]

Cloud, IPv6 and all-optical network

Seata 与三大平台携手编程之夏,百万奖金等你来拿

Machinery -- nx2007 (UG) finite element analysis tutorial 2 -- assembly
![[Thesis Writing] English thesis writing guide](/img/59/88d34814a88a2da19ed6a236825649.png)
[Thesis Writing] English thesis writing guide

The 8th "Internet +" competition - cloud native track invites you to challenge
![[deep learning compilation] operator compilation IR conversion](/img/10/bdcabde772e65eebc93f870f597524.png)
[deep learning compilation] operator compilation IR conversion
随机推荐
Solution to webkitformboundaryk in post request
[MRCTF2020]Ezpop-1|php序列化
Sklearn notes: make_ Blobs generate clustering data
The Web3 era is coming? Inventory of five Web3 representative projects | footprint analytics
How does webapi relate to the database of MS SQL?
The 8th "Internet +" competition - cloud native track invites you to challenge
Mysql 监控5
[three.js] Web3D first experience
Cookie加密13
Solving plane stress problem with MATLAB
利用tsne将不同句子关于相似度可视化出来
Sentinel source code analysis Part 7 - sentinel adapter module - Summary
Seata et les trois plateformes travaillent main dans la main pour programmer Summer, un million de bonus vous attend
Vl6180x distance and light sensor hands-on experience
Precautions for postoperative fundus hemorrhage / / must see every day
How did the data center change from "Britney Spears" to "Mrs. bull"?
Kwai reached out to the "supply side" to find the "source" of live broadcast e-commerce?
Visual Studio 2017 无法打开包括文件: “QOpenGLFunctions_3_3_Core”: No such file or directory
首届技术播客月开播在即
浅析现代Web端im即时通讯开发技术