zoukankan      html  css  js  c++  java
  • 递增数据插入表

    Excel中实现每次加1很方便,比如100,垂直向下的单元格是101,然后是102,103…选中100,101然后向下拉,拉到你想要的那个数字就OK 了。

    数据库怎么办?

    比如从100开始到999:

    一步一步来吧,首先要能生成100到999的数字,用下面这个语句(别试,有问题)

    declare @num numeric(3,0);
            set @num =100;
    while (@num <= 999)
    begin
    print @num
    set @num = @num+1
    end

    运行了好一会都没停的意思,我就点取消了,下面的提示是溢出,999+1就不在numeric(3,0)范围内了,把改为numeric(4,0)试下

    declare @num numeric(4,0);
            set @num =100;
    while (@num <= 999)
    begin
    print @num
    set @num = @num+1
    end

    0秒0行,打印出的结果是从100到999的

    那我现在想的是把结果插入到表中,那就先建个表

    create table TestNum(num numeric(4,0) primary key);

    然后再插入到表中,插入就是insert into,但值可以是@num变量?

    不行的,原理我不知道,只是我试过了,有报错

    上网搜了,用select就OK了

    declare @num numeric(4,0);
            set @num=100;
    while (@num <= 999)
    begin
    insert into TestNum select @num
    set @num = @num+1
    end;
     

    select * from TestNum;

    image

     
  • 相关阅读:
    clear ,refresh,free
    记录一次vxworks下使用NFS组件的过程
    [dart学习]第七篇:类(构造函数)
    [dart学习]第六篇:流程控制语句
    [沉痛哀悼宁滨院士]
    [dart学习]第五篇:操作符
    [dart学习]第四篇:函数
    [dart学习]第三篇:dart变量介绍 (二)
    [dart学习]第二篇:dart变量介绍 (一)
    [dart学习]第一篇:windows下安装配置dart编译环境,写出helloworld
  • 原文地址:https://www.cnblogs.com/cnmarkao/p/3757439.html
Copyright © 2011-2022 走看看