Inserting into a column with an identity column

I have two tables Alpha and Beta. I want to copy all of the records from Alpha into Beta, except for the "Id" column values of Alpha, which should be ignored. They should be ignored because the Beta "Id" values are auto incremented. So in other words, I just want to copy the "Name" column of Alpha into Beta. Assuming that when the insert occurs, the Beta Id values will automatically be added because they are auto incremented values. Can someone help me write the insert statement. I can't get it to work, because I don't know how to make the insert statement ignore the Id column on insert.

USE [Gimbro]
GO
/****** Object:  Table [dbo].[Alpha]    Script Date: 3/18/2015 4:41:08 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Alpha](
      [Id] [int] NULL,
      [Name] [varchar](50) NULL
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Beta]    Script Date: 3/18/2015 4:41:08 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Beta](
      [Id] [int] IDENTITY(1,1) NOT NULL,
      [Name] [nvarchar](50) NULL
) ON [PRIMARY]

---------------Now add data to Alpha table----
GO
INSERT [dbo].[Alpha] ([Id], [Name]) VALUES (0, N'Malicter')
GO
INSERT [dbo].[Alpha] ([Id], [Name]) VALUES (0, N'James')
GO
INSERT [dbo].[Alpha] ([Id], [Name]) VALUES (0, N'Jelly')
GO
INSERT [dbo].[Alpha] ([Id], [Name]) VALUES (0, N'Germosoli')
GO
LVL 2
brgdotnetcontractorAsked:
Who is Participating?
 
arnoldCommented:
why would you want to have two tables having the same information excluding Id column)?

You can do insert into beta (select column1, column2, column3, ... From alpha)

Insert into beta (columns,.....) values (
..

You have to explicitly state which columns and corresponding data is included.
0
 
brgdotnetcontractorAuthor Commented:
My friend, I posted this because I was actually working with a bigger table and just made some small examples. I could not get it to work, and now I feel silly, because it works now. Blush, Blush. Thank you for you're help.

INSERT INTO Beta select Name from Alpha
0
 
brgdotnetcontractorAuthor Commented:
I made a mistake, and did not realize an error I had made, but now my code is working. Thanks.
0
 
arnoldCommented:
Glad I could help,  while I do not know the purpose, I would recommend preserving the Id reference from alpha table in beta table.
Presumably based on your last comment, you Alpha table was designed in a way that you now see a reason to restructure it.
Preserving the ID will/could maintain other table references to simplify transitions.

I.e. You have alpha, gamma, that have a relationship to alpha's ID. If my guesstimate in the reason is correct, you would also need to transition gamma table as well to match the new beta tables ID column.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.