数据库增删查改、多表联查、基本操作总结 入职三天,还没上手项目,简单地学习了一下数据库的基本操作以及了解业务逻辑。
数据库的增删查改
*数据的insert语句 : insert into table values() insert into table (column1,column2,column3)values()数据的select语句 select * from table (where column = ) select column1,column2 from table (where column = ).数据的update语句 update table set column = ? where column = ?数据的delete语句 delete from table where column = ?
数据的多表联查
join联查 select a.column 1,a.column2,b.column1,b.column2,c.cloumn1,c.column2 from A a join C c on a.column = c.column join B b on a.column = b.columnmerge into 查询 merge into A a using (select a,b,c,d,e,f from B union select a,b,c,d,e,f from C union select a,b,c,d,e,f from D)b on a.column = b.column when matched then update set column = ? when not matched then insert (a,b,c,d,e,f)values (?,?,?,?,?)
基本操作
时间格式:convert(varchar(20),字段名,格式代码) 比如,2020/7/1 代码为111;2020-7-1代码为120
当值为null时给其赋值 select isnull(字段名,‘??’) 注:不同数据库有所不同,有的是ifnull
时间增减 DateAdd(year/month/day,±time,字段名)
当为某值时赋值,以及其他
输出系统时间 convert (char(30),getDate(),120)
截取 select substring(字段名,起始位,长度)