當前位置:首頁 » 編程語言 » 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

熱點內容
戰地一有什麼不用加速器的伺服器 發布:2025-07-10 08:51:33 瀏覽:404
linux怎麼看自己伺服器的ip 發布:2025-07-10 08:51:29 瀏覽:135
怎麼寫腳本刷視頻 發布:2025-07-10 08:49:51 瀏覽:381
安卓微信在哪裡設置鈴聲 發布:2025-07-10 08:48:05 瀏覽:232
dropbear編譯 發布:2025-07-10 08:27:35 瀏覽:684
我的世界電腦建造伺服器推薦 發布:2025-07-10 08:13:08 瀏覽:401
如何提高存儲數據的速度 發布:2025-07-10 07:55:57 瀏覽:259
規范c語言代碼 發布:2025-07-10 07:55:57 瀏覽:516
在線砍價源碼 發布:2025-07-10 07:55:56 瀏覽:796
編程工作年限 發布:2025-07-10 07:44:42 瀏覽:143