Here's a short script that shows how to add a new column to the existing table and fill in the relevant data:
-- Here I'm just setting up the tables with your example data.
create table [Table 1] (Col1 varchar(16), Col2 int, Col3 int);
create table [Table 2] (Col1 varchar(16), id_desc varchar(16));
go
insert into [Table 1] values
('Bdh', 6, 28435),
('Bdh', 2, 69),
('dwd', 0, 57),
('dwd', 8, 9742);
insert into [Table 2] values
('Bdh', 'good'),
('dwd', 'excellent');
go
-- First, add the column. It must either be nullable or have a default value,
-- since there are extant records.
alter table [Table 1] add id_desc varchar(16) null;
go
-- Now merge the data from [Table 2] into the new column.
update [Table 1]
set id_desc = T2.id_desc
from
[Table 1] T1
inner join [Table 2] T2 on T1.Col1 = T2.Col1;
Afterward, you can alter the column to be non-nullable if you wish; I've just made it null initially because SQL Server needs to have some default value that it can insert into the new column for existing rows.
There are plenty of ways to do the last part if you don't like the UPDATE...FROM
syntax; for instance, you can use MERGE
or a CTE with an UPDATE
.
Finally, I mentioned this in a comment above, but you might also consider creating a view:
create view Table1VW as
select
T1.Col1,
T2.id_desc,
T1.Col2,
T1.Col3
from
[Table 1] T1
inner join [Table 2] T2 on T1.Col1 = T2.Col1;
You may have some reason why you'd rather modify your table instead, but in the absence of such a reason, this might be a good alternative as it avoids redundant data storage and possible consistency issues later.