如何通过加入现有两个表的所有字段来创建新表? [英] how to create new table by joining all fields of existing both tables?

查看:78
本文介绍了如何通过加入现有两个表的所有字段来创建新表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的查询是

 创建  CandidateDetails  as  
select c.Status,c.InterviewDate,c.InterviewerName, c.DateOfConfirmation,c.DateOfJoining,c.LastWorkday,
c.Contact,d.DesignationOffered,d.Duration,d.SalaryOffered)
from CandidateSelection1 c join 指定d on c.CandidateId = d.DesignationId

解决方案

假设这是一次性查询,我会稍微改为以下



< pre lang =SQL> 选择 c.Status,c。InterviewDate,c.InterviewerName,c.DateOfConfirmation,c.DateOfJoining,c.LastWorkday,c .Contact, d.DesignationOffered,d.Duration,d.SalaryOffered
into newTab leName
来自 CandidateSelection1 c join 指定d
on c.CandidateId = d.DesignationId





创建你的桌子后你将会然后只需要定义主键等。


在SQL Server 2012中引入了创建表作为文件表的能力(根据您的示例),并且您已经标记了SQL-server- 2008R2这对你不起作用。



实现你想要的最简单方法是使用 SELECT INTO [ ^ ]



 选择 c.Status,c.InterviewDate,c.InterviewerName,c.DateOfConfirmation,c.DateOfJoining,c.LastWorkday,
c.Contact,d.DesignationO flad,d.Duration,d.SalaryOffered)
into CandidateDetails
from CandidateSelection1 c join 指定d on c.CandidateId = d.DesignationId


my query is

create table CandidateDetails as
(select c.Status,c.InterviewDate,c.InterviewerName,c.DateOfConfirmation,c.DateOfJoining,c.LastWorkday,
       c.Contact,d.DesignationOffered,d.Duration,d.SalaryOffered)
from CandidateSelection1 c join Designation d on c.CandidateId=d.DesignationId

解决方案

Assuming that this is a one off query, I would change it slightly to the following

select c.Status,c.InterviewDate,c.InterviewerName,c.DateOfConfirmation,c.DateOfJoining,c.LastWorkday, c.Contact,d.DesignationOffered,d.Duration,d.SalaryOffered
into newTableName
from CandidateSelection1 c join Designation d
on c.CandidateId=d.DesignationId



after it has created your table you will then just need to define your primary keys etc.


The ability to create a table as a filetable (as per your example) was introduced in SQL Server 2012 and you have tagged SQL-server-2008R2 so that won't work for you.

The easiest way to achieve what you are trying is to use SELECT INTO[^]

select c.Status,c.InterviewDate,c.InterviewerName,c.DateOfConfirmation,c.DateOfJoining,c.LastWorkday,
       c.Contact,d.DesignationOffered,d.Duration,d.SalaryOffered)
into CandidateDetails
from CandidateSelection1 c join Designation d on c.CandidateId=d.DesignationId


这篇关于如何通过加入现有两个表的所有字段来创建新表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆