SQL server中的一些的操作

2021-10-04 20:17:03 字數 1245 閱讀 6571

–提取日期中的年月日

declare @dev int,@len int,@i int=1,@date char(10),@day int,@month int

set @date=convert(char(10),dateadd(dd,-1,getdate()),120)

print @date

select @day=datepart(day,@date)

select @month=datepart(month,@date)

print @day

print @month

–在指定日期上加減指定天數

declare @date int

set @date=convert(char(10),dateadd(dd,-1,getdate()),120)

–top後面跟變數要+括號

select top(@i) @dev=devicesettings_id from #tempdev

–實現在迴圈中換表的操作(使用exec執行含表變數的語句)

declare @month int=4

exec(『select [id],[devicesettings_id],[channelnumber],[amplitude],[frequency],[energy] ,[alarm],[day] into ##tempinfo from [distributionnetwork_4g_2020].[dbo].[data』+@month+』]』+』 where [devicesettings_id]=』+@dev+』 and [day]=』+@day)

–儲存過程的書寫

great proc 過程名

–定義各個變數

@1,@2,…as

begin

**塊(即sql語句集合)

end上述完成了乙個儲存過程的書寫,刪除乙個儲存過程使用(drop proc 過程名)語句,更改儲存過程時將create改為alter,然後在**塊裡修改**,修改完之後執行一遍即可。呼叫儲存過程使用(call 過程名)

–事務事務一旦開始,不可停止,其結果只有兩種,要麼失敗回滾,要不成功提交。事務功能主要優勢在於其回滾能力,即當事務執行失敗的時候,會將操作所涉及到的資料回滾到事務執行前的狀態。只有進行了提交操作的事務才會對資料做出更改。

事務的建立步驟:

1:開啟事務 begin transaction

2:編寫事務邏輯

3:當失敗時回滾,使用rollback

當成功時提交,使用commit

關於CollectionView的一些操作記錄

通過重寫uicollectionviewflowlayout中的layoutattributesforelementsinrect方法可以讓uicollectionview顯示諸如瀑布流 水平流動布局等各種樣式的布局。其原理就是layoutattributesforelementsinrect方法本...

sqlServer 一些常用的

1.插入資料 insert into t casename name,plantid,factoryid,mouldclassid,casequery values 旋轉蓋 1,1,297,8 2.表中新增字段 alter table table name add column name datat...

docker的一些實操筆記

2.啟動nginx docker run name nginx p 80 80 d nginx 這樣就簡單的把nginx啟動了,但是我們想要改變配置檔案nginx.conf 進入容器,命令 docker exec it nginx bash nginx.conf配置檔案在 etc nginx 下面,...