修改数据表名和列名
修改列名
alter table [table_name] change [old_column_name] [new_column_name] [data_type]
- 只改列名:data_type 和原来一样,old_column_name !=new_column_name,data_type不变
- 只改数据类型:old_column_name = new_column_name , data_type改变
- 列名和数据类型都改变:如代码所示
修改表名
alter table [table_name] rename [new_table_name]
例子:
alter table account rename newaccount
Where的in操作符使用
select *from 表名 where 列名 in (value1,value2 ...)
select *from 表名 where 列名 in (select 列名 from 表名)
注解:
列名 in (value1,value2 …)等同 列名 = value1 or 列名 = value2 …
select distinct(精确的)
select distinct col_name from table_name ;
例子
select distinct title from book
insert into 与 select组合使用
一般用法:
insert into [表名] values(值1,值2, ...)
insert into [表名] (列1,列2 ... )values(值1,值2,...)
Insert into 与select的组合用法
insert into [表名1] select 列1,列2 from [表名2]
insert into [表名1] (列1,列2) select 列3,列4 from [表名2]
where 语句中between操作符(在。。。之间)
select *from 表名 where 列名 between 值1 and 值2
select *from 表名 where 列名 not between 值1 and 值2
like操作符
select *from 表名 where 列名 [not] like pattern
pattern:匹配模式,比如:‘abc’ ,’%abc’,‘abc%’,‘%abc%’;
‘%’是个通配符,理解上可以把它当成任何字符串
例子
‘%abc’ 能匹配 ‘ettrabc’