SQL inserts N data records every five seconds.

Source: Internet
Author: User

SQL inserts N data records every five seconds.

1. Create a data table

Create table projectManage (ID int identity primary key not null, projectName nvarchar (20) not null, manager_1 nvarchar (10) not null, manager_2 nvarchar (10) not null, monitor nvarchar (10) not null, isFire varchar (2) null, startTime datetime not null, endTime datetime not null, manager_1tel nvarchar (11) not null, manager_1company nvarchar (20) not null, manager_2tel nvarchar (11) not null, manager_2company nvarchar (20) not null, monitortel nvarchar (11) not null, monitorcompany nvarchar (20) not null) select * from projectManageinsert projectManage values ('installation set', 'xiaoming ', 'daming', 'engineering supervisor ', 'yes', '2017-9-9', '2017-9-9 ', '123', '123', '123', '123', '123', '123 ')View Code

 

2. Use the while loop to insert a data record every five seconds. declare @ dt datetime, @ today datetime, @ a varchar (max ), @ z datetime set @ a = 0 select @ today = CONVERT (varchar (100), GETDATE (), 20 ), @ dt = @ todaywhile @ a <1 beginselect @ today = CONVERT (varchar (100), GETDATE (), 20) while @ dt = @ today begin insert projectManage values ('installation bb '+ @ a, 'xiaoming', 'daming ', 'engineering supervisor', 'yes', @ dt, '2017-9-9 ', '20170101', '20160301', '20160301', '20160301', '20160301') set @ dt = DATEADD (SECOND, 5, @ dt) endset @ a = @ a-1endView Code

3. Insert N data records at a time

Declare @ I varchar (max) set @ I = 1 while @ I <1000001 begininsert projectManage values ('installation '+ @ I, 'xiaoming', 'daming ', 'engineering supervisor ', 'yes', '1996-9-9', '1996-9-9 ', '1234568', '1234568', '1234568 ', '123', '123') set @ I = @ I + 1endView Code

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.