如何在表列中乘以值?

时间:2022-02-05 13:42:47

I have to edit table in my database. I have column [Width] and I have to multiply this [Width] * 10 for all rows. How can I do it?

我必须在我的数据库中编辑表。我有列[宽度],我必须将所有行的[宽度] * 10相乘。我该怎么做?

6 个解决方案

#1


5  

UPDATE TABLE
SET WIDTH = WIDTH * 10

#2


4  

You can do that by using UPDATE query like this:

您可以使用UPDATE查询执行此操作,如下所示:

UPDATE Mytable SET [Width] = [Width] * 10

Normal syntax is:

正常的语法是:

UPDATE <table_name> SET <column_name> = <value> [WHERE <condition>]

But since you want to update all records you don't need to add WHERE condition.

但是,由于您要更新所有记录,因此不需要添加WHERE条件。

For more see UPDATE (Transact-SQL) and UPDATE Basics in SQL Server

有关更多信息,请参阅SQL Server中的UPDATE(Transact-SQL)和UPDATE基础知识

#3


3  

UPDATE mytable SET myfield = myfield * 10

#4


3  

update table_name set column_name = [width] * 10

#5


1  

You can do it like this:

你可以这样做:

update YourTable
   set [Width] = [Width] * 10

#6


1  

You can update the column by using the update statement and use the OUTPUT clause to give you and idea of the changes (if you are using 2008 +). Put the whole thing in a transaction and rollback if you have any doubts and commit the changes at your leisure.

您可以使用update语句更新列,并使用OUTPUT子句为您提供更改(如果您使用的是2008 +)。如果您有任何疑问并在闲暇时提交更改,请将整个事务放在事务中并回滚。

BEGIN TRAN

UPDATE tablename SET width = width * 10 OUTPUT inserted.width, deleted.width

UPDATE tablename SET width = width * 10 OUTPUT inserted.width,deleted.width

ROLLBACK TRAN

--COMMIT TRAN

#1


5  

UPDATE TABLE
SET WIDTH = WIDTH * 10

#2


4  

You can do that by using UPDATE query like this:

您可以使用UPDATE查询执行此操作,如下所示:

UPDATE Mytable SET [Width] = [Width] * 10

Normal syntax is:

正常的语法是:

UPDATE <table_name> SET <column_name> = <value> [WHERE <condition>]

But since you want to update all records you don't need to add WHERE condition.

但是,由于您要更新所有记录,因此不需要添加WHERE条件。

For more see UPDATE (Transact-SQL) and UPDATE Basics in SQL Server

有关更多信息,请参阅SQL Server中的UPDATE(Transact-SQL)和UPDATE基础知识

#3


3  

UPDATE mytable SET myfield = myfield * 10

#4


3  

update table_name set column_name = [width] * 10

#5


1  

You can do it like this:

你可以这样做:

update YourTable
   set [Width] = [Width] * 10

#6


1  

You can update the column by using the update statement and use the OUTPUT clause to give you and idea of the changes (if you are using 2008 +). Put the whole thing in a transaction and rollback if you have any doubts and commit the changes at your leisure.

您可以使用update语句更新列,并使用OUTPUT子句为您提供更改(如果您使用的是2008 +)。如果您有任何疑问并在闲暇时提交更改,请将整个事务放在事务中并回滚。

BEGIN TRAN

UPDATE tablename SET width = width * 10 OUTPUT inserted.width, deleted.width

UPDATE tablename SET width = width * 10 OUTPUT inserted.width,deleted.width

ROLLBACK TRAN

--COMMIT TRAN