Home > Blockchain >  Is there a way to insert the same row values in a temp table? SQL Server
Is there a way to insert the same row values in a temp table? SQL Server

Time:08-25

I have a temp table #t that has a column already called ID with about 75 values. I've inserted another column called status and I want all of the values in the 'status' column to equal "A". Is there a way I can do this without having to manually insert A for each row?

Would want it to look like this but for all 75 rows

|ID|   |Status|
----------------
|24|   |  A   |

CodePudding user response:

Not sure if I understand your question correctly but you could do it with something like

update #t set Status = 'A'

CodePudding user response:

You can do that by setting the default value for status column.

Create table #test(id int, status varchar(1) default 'A');
insert into #test (id) values (1),(2),(3);

Select * From #test;

id  status
1   A
2   A
3   A

If your table is already created you may set the default value as the following:

ALTER TABLE #test ADD CONSTRAINT df_val DEFAULT 'A' FOR status;

See a demo from db<>fiddle.

  • Related