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