當前位置:首頁 » 編程語言 » sql數列

sql數列

發布時間: 2023-02-12 23:47:24

1. 如何用T-sql 產生1到100的數列

1、用循環做
WHILE @i <- 100
BEGIN
...

END

2、批量自插入
A)建一個表TableX(ID, Code),其中ID欄位設置為IDENTITY(1, 1)

B)插入一條記錄

C)反復自插入(使用下述SQL),7次後超過100條了
INSERT INTO TableX
SELECT ...
FROM TableX

D)查詢此表的ID<=100的數據
SELECT ID
FROM TableX
WHERE ID <= 100

2. 用SQL server寫一個存儲過程,輸出數列1 1 2 3 5 8 13

第一步:點擊資料庫下的「可編程性」,選擇「存儲過程」,點擊滑鼠右鍵,選擇「新建存儲過程」

第二步:在create PROCEDURE 後 輸入存儲過程的名字,緊跟著的就是定義存儲過程的參數,接下來就可以去編寫自己所需要組裝的存儲過程語句了
注意,怕寫的不對,可以執行下,想驗證sql語句是否正確,就使用print輸出下

第三步:點擊上面的執行,存儲過程就寫好了,要怎麼調用呢,在sqlserver的語句查詢框中,輸入exec 存儲過程名 參數,執行就可以了。

3. sqlserver中遞增數列標識的問題

dbcc checkident(『表名』,reseed,0)

或者
SET IDENTITY_INSERT [ database_name . [ schema_name ] . ] table { ON | OFF }
set identity_insert talbeName on
這樣可以手動更改標識列

也可以
Alter table talbeName Drop Column ColumnName
Alter table talbeName Add ColumnName Int IDENTITY(1,1)

4. 使用sql語句寫一個函數計算一個數列的累計和

統計一個班的學生成績

select student_no,sum(grade) from student group by student_no

5. sql自動生成自然數列怎麼寫

select a.col*1000+b.col*100+c.col*10+d.col+1 as col

from

(select 0 as col union all select 1 union all select 2 union all

select 3 union all select 4 union all select 5 union all

select 6 union all select 7 union all select 8 union all select 9)a

cross join

(select 0 as col union all select 1 union all select 2 union all

select 3 union all select 4 union all select 5 union all

select 6 union all select 7 union all select 8 union all select 9)b

cross join

(select 0 as col union all select 1 union all select 2 union all

select 3 union all select 4 union all select 5 union all

select 6 union all select 7 union all select 8 union all select 9)c

cross join

(select 0 as col union all select 1 union all select 2 union all

select 3 union all select 4 union all select 5 union all

select 6 union all select 7 union all select 8 union all select 9)d

order by col

熱點內容
開伺服器時如何開pvp 發布:2025-09-17 03:02:23 瀏覽:969
安卓手機序列號a開頭什麼意思 發布:2025-09-17 02:59:26 瀏覽:689
機房電腦重裝以後伺服器不能識別 發布:2025-09-17 02:59:17 瀏覽:156
百度雲伺服器主機地址 發布:2025-09-17 02:59:17 瀏覽:55
dijkstra演算法過程圖解 發布:2025-09-17 02:50:46 瀏覽:313
怎麼看自己我的世界伺服器ip 發布:2025-09-17 02:39:43 瀏覽:898
abapsqlin 發布:2025-09-17 02:37:18 瀏覽:991
安卓手機怎麼恢復ps的照片 發布:2025-09-17 02:14:22 瀏覽:422
android仿百度 發布:2025-09-17 02:12:53 瀏覽:606
木瓜奇跡腳本 發布:2025-09-17 01:54:25 瀏覽:412