Beego 学习比较8:SQL语句

时间:2023-03-09 13:39:27
Beego 学习比较8:SQL语句

SQL语句

1>     常用的SQL语句

1->新增  insert into 表名(字段A,字段B,…) Values(字段A值,字段B值,…)

2->更新  update 表名 set 字段A=字段A值,字段B=字段B值 where 条件

3->删除  delete from 表名 where 条件

2>     单表SQL查询语句

1-> SQL书写的顺序:select (distinct) 字段A,字段B,… from 表名 where 条件A  group by 字段C  having条件B order by 字段D (asc,desc)

2->SQL执行的顺序: from表名where条件A group by字段C  having 条件B select (distinct) 字段A,字段B,… order by 字段D (asc,desc)

3>     多表操作SQL语句

1->完全连接  select  a.字段A,a.字段B,b.字段A,b.字段B from 表名 a,表名b where a. 关联字段=b.关联字段

2->左连接  select  a.字段A,a.字段B,b.字段A,b.字段B  from   a   left   join   b     on  a. 关联字段=b.关联字段

3->右连接  select  a.字段A,a.字段B,b.字段A,b.字段B   from   a   right   join   b     on   a. 关联字段=b.关联字段

4->内连接  select  a.字段A,a.字段B,b.字段A,b.字段B  from  a   inner  join  b    on  a. 关联字段=b.关联字段

4>     存储过程

create proc | procedure pro_name

[

{@参数数据类型} [=默认值] [output],

{@参数数据类型} [=默认值] [output],

....

]

as

SQL语句

Go

查看结果:exec  proc_ name  [参数A的值,参数B的值,…]

5>     触发器

1->创建触发器

create  trigger  trigger_name

on {table_name | view_name}

{for | After | Instead of }

[ insert, update,delete ]

as

SQL语句

Go

理解:在那张表/那个视图上创建了一个触发器,这个触发器是在SQL执行语句的之后/还是替代SQL语句执行,触发器的类型是insert(插入),update(更新),delete(删除)

2->删除触发器:

基本语句如下:

  drop trigger trigger_name

6>     下一章记录使用BootStrap布局