I’ve merged a three tables into one table and I’ve noticed that each merged table has similar data columns producing redundancy.
What is the best way to update all of these columns into one column?
Right now the data will read
WallJambHeadCut | WallJambSillCut | DoorJambSillCut | DoorJambHeadCut | ect ....
1 0 0 0
0 0 1 0
The above needs to be condensed down too two columns:
Headcut | SillCut
In other words each one of these columns can be condensed into one. I just want to make sure that I write the correct update statement because I would hate the jack my data up.
CREATE TABLE [dbo].[Table_1](
[ID] [int] IDENTITY(1,1) NOT NULL,
[WallJambHeadCut] [bit] NOT NULL,
[WallJambSillCut] [bit] NOT NULL,
[DoorJambSillCut] [bit] NOT NULL,
[DoorJambHeadCut] [bit] NOT NULL,
[VerticalHeadCut] [bit] NOT NULL,
[VerticalSillCut] [bit] NOT NULL,
CONSTRAINT [PK_Table_1] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
Depending on the complexity you want to do, you can replace all the columns with a column of type tinyint and do bitwise operations to handle the data. We actually do that in the project I’m working on.
For the example you gave, you will have
Whenever you need to update these values you just use the operators.
You can check more information here http://msdn.microsoft.com/en-us/library/ms176122.aspx
The tinyint is better because it only occupies 8 bits
Cheers