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

    递增数据插入表,我们还可以使用生成随机数来填充,建表的时候使用约束,不能重复,重复的话自然就不插入,继续生成下一个不重复的随机数。

    还是以之前的为例,插入表中的数据为100-999。我们不谈性能(插入数据量小速度也很快的),只谈逻辑。

    create table TestNum(num numeric(3,0) unique,check (num between 100 and 999));
    go
    declare @num int
    set @num=(select COUNT(*) from TestNum)
    while (@num < 900) 
    begin
    insert into TestNum 
    select round(RAND(CHECKSUM(newid()))*1000,0)
    set @num = (select count(*) from TestNum)
    end;
    go
    select COUNT(*) from TestNum;
    go
    select * from TestNum order by 1;
    go

    上面的插入可能只是某个需求中最基础的实现,比如下面的111000到111999,前面111不变,后面的改变。实际应用可以生成特定号码段的号码

    create table TestNum(num numeric(6,0) unique,check (num between 111000 and 111999));
    go
    declare @num int
    set @num=(select COUNT(*) from TestNum)
    while (@num < 1000) 
    begin
    insert into TestNum 
    select cast('111'+right('000'+convert(nvarchar(6),round(RAND(CHECKSUM(newid()))*1000,0)),3) as numeric(6,0))
    set @num = (select count(*) from TestNum)
    end;
    go
  • 相关阅读:
    精确计算微信小程序scrollview高度,全机型适配
    精确计算微信小程序scrollview高度,全机型适配
    七牛云赵之健:多维度融合赋能视频 AI 的实践
    javaweb学习总结(四十)——编写自己的JDBC框架
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    深度学习入门笔记(十三):批归一化(Batch Normalization)
    4G EPS 中的 Control Plane
    4G EPS 中建立 eNB 与 MME 之间的 S1 连接
  • 原文地址:https://www.cnblogs.com/cnmarkao/p/3760581.html
Copyright © 2011-2022 走看看