
insert into 的用法,我想将一个表中的数据导入到一个自定义的表中
insertintoA表中的数据复制一份到B表。删除A表里的数据再将B表里的数疽导入A表中去...
insert into
A表中的数据复制一份到B表。删除A表里的数据再将B表里的数疽导入A表中去 展开
A表中的数据复制一份到B表。删除A表里的数据再将B表里的数疽导入A表中去 展开
展开全部
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
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
假设两表结构相同:
insert into b select * from a
delete a
insert into a select * from b
insert into b select * from a
delete a
insert into a select * from b
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
insert into B
select * from A
go
select * from A
go
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询