基本sql 語句(某些只是適用於sql server)

1.getdate()內值函數的使用,用於獲取當前時間,如某一個表中有一列爲uqdatetime:顯示這裏以詩句的最後更新時間。語句爲:
update persons set updatetime=GETDATE ()  其中persons是表updatetime是欄位。注意:這裏的表updatetime是早就建好了的
2.在表中增加一個欄位:alter table persons add updatetime datetime  其中datetime是數據類型
3.修改表的某一列數據的數據類型:alter table persons alter column updatetime  datetime


4.isnull()函數 :用於排除列爲null干擾時所用 isnull(列名,0)意思爲該列爲null時返回0.
5.having:官方解釋爲:在 SQL 中增加 HAVING 子句原因是,WHERE 關鍵字無法與合計函數一起使用。在我的理解中就是相當於增加條件了 只是這個條件是個合計函數,例如:
select customer ,sum(orderprice) from Orders
where customer="條件1"or customer="條件2"
group by customer
having sum(orderprice)>1500

6.select FORMAT (getdate (),'YYYY-MM-DD')
   select FORMAT (getdate (),'yyyy-MM-dd')
這兩種語句在Microsoft SQLserver Management Studio 2012中運行時有一些奇怪的現象(親自去試試哦!)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章