Mysql grammar details (1)

Modify data table name and column name

Modify column names

alter table [table_name] change [old_column_name] [new_column_name] [data_type]
  1. Only change the column name: data_type is the same as before, old_column_name !=new_column_name, data_type remains unchanged
  2. Only change the data type: old_column_name = new_column_name , data_type changed
  3. Both column names and data types are changed: as shown in the code

Modify table name

alter table [table_name] rename [new_table_name]

example:
alter table account rename newaccount

Where's in operator use

select *from 表名 where 列名 in (value1,value2 ...)
select *from 表名 where 列名 in (select 列名 from 表名)

annotation:

column name in (value1, value2...) is equivalent to column name = value1 or column name = value2...

select distinct (exact)

select distinct col_name from table_name ;

example

select distinct title from book

insert into is used in combination with select

General usage:

insert into [表名] values(值1,值2, ...
insert into [表名] (列1,列2 ... )values(值1,值2...)

The combined usage of Insert into and select

insert into [表名1] select1,列2 from [表名2]
insert into [表名1] (列1,列2) select3,列4 from [表名2]

The between operator in the where statement (between... )

select *from 表名 where 列名 between 值1 and2
select *from 表名 where 列名 not between 值1 and2

like operator

select *from 表名 where 列名 [not] like pattern

pattern: matching pattern, such as: 'abc', '%abc', 'abc%', '%abc%';
'%' is a wildcard, it can be understood as any string

example

'%abc' matches 'ettrabc'

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324821090&siteId=291194637