1. 程式人生 > 其它 >Golang構建HTTP服務(一)--- net/http庫原始碼筆記

Golang構建HTTP服務(一)--- net/http庫原始碼筆記

三大資料型別:

字串

varchar

   

數值

int

   

日期

data、time

       

增、刪、改、查:

增:

insert into

   

刪:

 delete from  <表名>

   

改:

update <表名> set 欄位

   

查:基本查詢:select * from <表名>

   

        查詢字句:where: select * from <表名> where 條件

 

    

                           排序:select * from <表名> order by <按照某個欄位排序>

   

                           分組:select * from <表名> group by <按照某個欄位分組>

   

                           去重:select distinct<欄位名> from <表名>

       

表關聯查詢:兩表關聯:內連線 inner join:select t1(*),t2(*) from t1 inner join t2 on t1.id=t2.id;

                      左連線 left join : select t1(*),t2(*) from t1 left join t2 on t1.id=t2.id;

                      右連線 right join: select t1(*),t2(*) from t1 right join t2 on t1.id=t2.id;

                      全連線 左連線union 右連線: select t1(*),t2(*) from t1 left join t2 on t1.id=t2.id

Union

select t1(*),t2(*) from t1 right join t2 on t1.id=t2.id;

 

            三表關聯:表一關聯表二,再關聯表三: select e(*),t3(*)from(select t1(*),t2(*),t3(*) from t1 left join t2 on t1.id=t2.id

) e

Left join select e(*),t2(*) from e left join t3 on e.id=t3.id;

 

 

子查詢:單個值:select name from t1 where age in (1);

        多個值作為範圍:select name from t1 where age in (1,10);

        多個值作為中間結果:select name from t1 where age in (select age from t2 where age >10);

 

檢視:建立檢視:create view v_a(編號,姓名)as select * from a with check option;

      建立多表檢視:create view v_abc(編號,姓名,年齡)as select a.id,a.name,b.age from a,b where a.id = c.id with check option;

 

索引:普通索引:直接建立索引:create index index_name on table (column)

                修改表結構新增索引:alert table table_name index index_name(column);

      唯一索引:create unique index index_name on(column);

      複合索引:create index index_name on table (name,age,id)

 

 

事務:開啟:begin

      提交:commit

      回滾:rollback

 

觸發器:create trigger t_name

         Insert/delete/update/alert on <表名>

         For each row

           Begin

            Sql語句

           End;

 

儲存過程:create procedure test()

          Begin

             Select * from user;

          End;

 

查詢優化:

  1. count的優化
  2. 避免使用不相容的資料型別
  3. 索引欄位上進行運算會使索引失效
  4. 避免使用in\!=\<>\is null\not null\not in這樣的欄位
  5. 合理使用exists,not exists字句
  6. 儘量使用數字型欄位
  7. 模糊查詢 where like,'L%'可以使用索引,'%L%'不可以使用
  8. 不要在選擇的欄位上放置索引,這是無意義的。應該在條件選擇的語句上合理的放置索引,比如where,order by。
  9.  程式中如果一次性對同一個表插入多條資料,把它拼成一條語句執行效率會更高。
  10. 欄位資料型別優化