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

熱點內容
聯通吉林省dns伺服器地址 發布:2025-09-17 01:26:56 瀏覽:957
python列表刪除指定元素 發布:2025-09-17 01:26:13 瀏覽:939
安卓手機設置安全管理器有什麼用 發布:2025-09-17 01:23:32 瀏覽:897
mysql資料庫備份的方法 發布:2025-09-17 01:22:55 瀏覽:569
c語言中函數返回值的類型是由 發布:2025-09-17 01:21:16 瀏覽:885
編譯原理實驗三 發布:2025-09-17 00:57:50 瀏覽:894
近親繁殖演算法 發布:2025-09-17 00:48:47 瀏覽:695
安卓如何關閉浮屏球 發布:2025-09-17 00:23:23 瀏覽:921
下列存儲器中存取周期最短的是 發布:2025-09-17 00:16:20 瀏覽:243
如何查詢域名用的伺服器地址 發布:2025-09-17 00:04:01 瀏覽:807