[英]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.我有一个临时表#t,其中有一列已经称为 ID,其中包含大约 75 个值。 I've inserted another column called status and I want all of the values in the 'status' column to equal "A".我插入了另一个名为 status 的列,我希望“status”列中的所有值都等于“A”。 Is there a way I can do this without having to manually insert A for each row?有没有一种方法可以做到这一点,而不必为每一行手动插入 A?
Would want it to look like this but for all 75 rows希望它看起来像这样,但对于所有 75 行
|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 .查看db<>fiddle的演示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.