当前位置:首页 » 编程语言 » 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-09-19 00:36:28 浏览:884
安卓系统在哪里输入网址 发布:2025-09-19 00:35:46 浏览:171
armlinuxgccgcc 发布:2025-09-19 00:35:37 浏览:425
wincachephp 发布:2025-09-19 00:30:28 浏览:863
如何给文件夹设置图标 发布:2025-09-19 00:06:09 浏览:750
火车头密码指纹锁多少钱 发布:2025-09-18 23:16:55 浏览:139
雪佛兰最高配置长什么样 发布:2025-09-18 23:16:54 浏览:173
网络通话源码 发布:2025-09-18 23:07:23 浏览:92
asp如何购买服务器 发布:2025-09-18 22:46:24 浏览:676
网页加密代码 发布:2025-09-18 21:56:12 浏览:175