文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>用SQL批量插入数据(转)

用SQL批量插入数据(转)

时间:2010-10-15  来源:lanru

INSERT INTO time_by_day

 
(time_id, the_date, the_year, month_of_year, quarter,day_of_month)

VALUES ('1101', '1999-10-1', '1999', '10', 'Q4','1')


2,单条插入:


INSERT INTO time_by_day

      (time_id, the_date, the_year, month_of_year, quarter, day_of_month)

SELECT TOP 1 time_id + 1 AS time_id, the_date + 1 AS the_date, YEAR(the_date + 1)

      AS the_year, MONTH(the_date + 1) AS month_of_year, { fn QUARTER(the_date + 1)

      } AS quarter, DAY(the_date + 1) AS day_of_month

FROM time_by_day

ORDER BY time_id DESC


3,循环插入:

 

DECLARE @MyCounter INT

SET @MyCounter = 0            /*设置变量*/

WHILE (@MyCounter < 2)     /*设置循环次数*/

BEGIN

WAITFOR DELAY '000:00:10'   /*延迟时间10秒*/

INSERT INTO time_by_day

      (time_id, the_date, the_year, month_of_year, quarter, day_of_month)

SELECT TOP 1 time_id + 1 AS time_id, the_date + 1 AS the_date, YEAR(the_date + 1)

      AS the_year, MONTH(the_date + 1) AS month_of_year, { fn QUARTER(the_date + 1)

      } AS quarter, DAY(the_date + 1) AS day_of_month

FROM time_by_day

ORDER BY time_id DESC


SET @MyCounter = @MyCounter + 1

END


4,插入以时间为变量的数据


DECLARE @MyCounter INT

declare @the_date datetime

SET @MyCounter = 0

SET @the_date = '1999-1-4'

WHILE (@MyCounter < 200000)

BEGIN

WAITFOR DELAY '000:00:10'

/*INSERT INTO time_by_day

      (time_id, the_date, the_year, month_of_year, quarter, day_of_month)

SELECT TOP 1 time_id + 1 AS time_id, the_date + 1 AS the_date, YEAR(the_date + 1)

      AS the_year, MONTH(the_date + 1) AS month_of_year, { fn QUARTER(the_date + 1)

      } AS quarter, DAY(the_date + 1) AS day_of_month

FROM time_by_day

ORDER BY time_id DESC

*/

insert into time_by_day (time_id,the_date)values('371',@the_date)

SET @the_date = @the_date + 1

SET @MyCounter = @MyCounter + 1

END

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载