sql-update

Return updated row attributes on UPDATE

折月煮酒 提交于 2020-12-29 05:29:47
问题 My query is as follow: UPDATE t1 SET t1.foreign_key = (SELECT id FROM t2 WHERE t2.col = %s ) WHERE t1.col = %s How do I return some attributes of the updated row in the table in the same query? 回答1: Use the RETURNING clause. The optional RETURNING clause causes UPDATE to compute and return value(s) based on each row actually updated. Any expression using the table's columns, and/or columns of other tables mentioned in FROM , can be computed. The new (post-update) values of the table's columns

I get an error “Error converting data type nvarchar to real.”

元气小坏坏 提交于 2020-12-26 11:24:33
问题 The code which I have is below, can you please inform me where the issue might be so we can drop the price by warehouse ID with 7%? private void button4_Click(object sender, EventArgs e) {​​​​​​​ try {​​​​​​​ myConnection = new SqlConnection(frm.cs); myCommand = new SqlCommand("update Inventory set Price=@Price where WarehouseCode=6", myConnection); myConnection.Open(); myCommand.Parameters.AddWithValue("@Price", "@Price * 0.7"); myCommand.ExecuteNonQuery(); myConnection.Close(); MessageBox

How to update models in VS 2019 from database in Entity Framework in ASP.NET Core

放肆的年华 提交于 2020-12-25 04:46:56
问题 By VS 2019, I created an API project (database first), everything it's working well, now I made some changes in the database like add new tables and some property and modify data type for others and so on.., the question is how to update models to match the database in SQL? this is a screenshot for my project: 回答1: Try to recreate your models via Scaffold-DbContext with "Force" param. Scaffold-DbContext "Data Source=yoursource;Initial Catalog=yourdb;Integrated Security=True;Connect Timeout=30

How to create and insert a JSON object using MySQL queries?

心已入冬 提交于 2020-11-30 06:46:49
问题 I'm trying to create a JSON object and then read the values from it into MySQL table. But I'm facing errors and I'm new to both JSON and MySQL. SET @j = '{"key1": "value1", "key2": "value2"}'; CREATE TABLE Person (name int,id int); INSERT INTO Person (name,id) SELECT * FROM OPENJSON(@j) WITH (name int,id int); 回答1: On creating table set your field as JSON datatype. CREATE TABLE `person` ( `name` json DEFAULT NULL ); And Insert JSON data into it, INSERT INTO `person` (`name`) VALUES ('["name1"