SQL server中學習過程中有用的小知識點

2021-07-05 00:10:53 字數 1611 閱讀 2095

1、在sqlserver

中查詢某個字段存在於那個表中的語句是:

use testgo

select a.name as tablename from sysobjects a inner

join syscolumns b on a.id=b.id

where b.name=

'列名'

例句:use digsmart70fl(此為資料庫名)go

select a.name as tablename from sysobjects a inner

join syscolumns b 

on  a.id=b.id where b.name=

'dtreceived'

2、印射兩個表的資訊

insert

into

pn_model_commisionscheme

(pk_group_model

,intyear

,intmonth

,product_no

,model_no

,commission_data

,employeetype

,categoryitemid

,pk_categoryitem)

select

pk_group_model

,intyear

,7 as

intmonth

,product_no

,model_no

,0,1,23,9 from

pn_group_model

where

intyear

=2015 and

intmonth

=7 and

active_flag=1

3、執行儲存過程語句

exec

sale_totalgroupbonusdata_2014

2015,7,39,8

exec

sale_totalproductbonusdata_2014

2015,7,39

exec

total_bonusdetailsinfo_2014

2015,7,39

exec

salary_updatebonusdetail

2015,7,39

4、刪除某錶的資訊

delete

from

pn_model_commisionscheme

where

intyear

=2015 and

intmonth

=75、

group by 

的用法

select

pr_model_name

,count

(*)from

pn_employee_sn

where

pk_employee

=26 and

saledate

between

'2015-07-01'

and'2015-07-31'

group

bypr_model_name

將同名的銷售量相加

sqlserver中在儲存過程中寫事務

由於對資料的操作經常需要併發,所以在儲存過程中使用事務是非常必要的,我經常這樣處理 if exists select from sys.objects where name sp drop proc sp gocreate procedure sp 引數列表.out bit 0 output 輸出引...

SQLServer 儲存過程中各種判斷是否為空

1.判斷是否存在這樣的記錄 if not exists 和 if exists 相對應 例 使用者是否存在 if not exists if exists select 1 from user nolock where username abcd begin print 使用者存在 end else...

SqlServer儲存過程中迴圈的使用

1.while迴圈 格式示例如下 declare iint set i 1 while i 30begin insert into test userid values i set i i 1end2.游標迴圈 格式示例如下 declare a1varchar 10 a2varchar 10 a3i...