在SQL SELECT语句中将查询结果存放在一个表中应该使用什么子句?
6个回答
2013-04-17
展开全部
创建两个表,Students 为A表,Students _Temp为B表,从A表取ID,UserName插入到B表中。第一,A表--Students CREATE TABLE [Students] (
[ID] [int] NOT NULL ,
[UserName] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
[Age] [int] NULL ,
[Sex] [char] (10) COLLATE Chinese_PRC_CI_AS NULL ,
CONSTRAINT [PK_Students] PRIMARY KEY CLUSTERED
(
[ID]
) ON [PRIMARY]
) ON [PRIMARY] --B表CREATE TABLE [Students_Temp] (
[ID] [int] NOT NULL ,
[UserName] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
[Age] [int] NULL ,
[Sex] [char] (10) COLLATE Chinese_PRC_CI_AS NULL ,
CONSTRAINT [PK_Students2] PRIMARY KEY CLUSTERED
(
[ID]
) ON [PRIMARY]
) ON [PRIMARY] 第二,A表插入实验数据insert into Students values (1,'zhangsan1',19,'man')
insert into Students values (2,'zhangsan2',19,'man')
insert into Students values (3,'zhangsan3',19,'man')
insert into Students values (4,'zhangsan4',19,'man')
insert into Students values (5,'zhangsan5',19,'man')
insert into Students values (6,'zhangsan6',19,'man')
insert into Students values (7,'zhangsan7',19,'man')
insert into Students values (8,'zhangsan8',19,'man') 第三,执行A表取数据插到B表中操作insert into Students_Temp(ID,UserName) select ID,UserName from Students 最后,查看B表Students_Temp中的数据select * from students_Temp
[ID] [int] NOT NULL ,
[UserName] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
[Age] [int] NULL ,
[Sex] [char] (10) COLLATE Chinese_PRC_CI_AS NULL ,
CONSTRAINT [PK_Students] PRIMARY KEY CLUSTERED
(
[ID]
) ON [PRIMARY]
) ON [PRIMARY] --B表CREATE TABLE [Students_Temp] (
[ID] [int] NOT NULL ,
[UserName] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
[Age] [int] NULL ,
[Sex] [char] (10) COLLATE Chinese_PRC_CI_AS NULL ,
CONSTRAINT [PK_Students2] PRIMARY KEY CLUSTERED
(
[ID]
) ON [PRIMARY]
) ON [PRIMARY] 第二,A表插入实验数据insert into Students values (1,'zhangsan1',19,'man')
insert into Students values (2,'zhangsan2',19,'man')
insert into Students values (3,'zhangsan3',19,'man')
insert into Students values (4,'zhangsan4',19,'man')
insert into Students values (5,'zhangsan5',19,'man')
insert into Students values (6,'zhangsan6',19,'man')
insert into Students values (7,'zhangsan7',19,'man')
insert into Students values (8,'zhangsan8',19,'man') 第三,执行A表取数据插到B表中操作insert into Students_Temp(ID,UserName) select ID,UserName from Students 最后,查看B表Students_Temp中的数据select * from students_Temp
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-04-17
展开全部
insert into 表1 select * from 表2 //表1存在的 select * from 表2 into 表1 //表1不存在的,新建一个表1
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-04-17
展开全部
sqlserver中SELECT COL1,COL2,COL3 INTO NEWTABLE FROM TABLE WHERE ......oracle中CREATE TABLE NEWTABLE AS SELECT COL1,COL2,COL3 FROM TABLE WHERE ....
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-04-17
展开全部
第一个答案是正确的。第二个瞎扯
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询