Insert Into的用法总结

1、将一张表的信息插入到另一张表中例子:
Insert Into tt
Values(id,title,pubtime)
select id,title,pubtime
from ww
where id = '0001'

2、用 VALUES 子句为一行指定数据值:
INSERT INTO MyTable (PriKey, Description)
      VALUES (123, 'A description of part 123.')

用 SELECT 子查询为一行或多行指定数据值。
INSERT INTO MyTable  (PriKey, Description)
      SELECT ForeignKey, Description
      FROM SomeView

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

转载于:https://www.cnblogs.com/ufo0303/archive/2006/08/18/480344.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值