简体   繁体   中英

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

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   |

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

update #t set Status = 'A'

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM