在SQL中更新无行(Update No Rows in SQL)
我有一个简单的SQL更新语句......
UPDATE [Table].[dbo].[Test] SET [Field1] = @Param1 WHERE [Field2] = @Param2
假设我的数据集仅包含以下信息......
Field 1 | Field 2 ------------------------- 123 | abc 456 | def 789 | ghi
我的问题就是这样......如果用户想要将'def'更新为'44',那么,哦,不! 他们不小心为'Param2'键上'露水'。 所以这是我们的参数集......
- Param1:444
- Param2:露水
根据我的测试,我得到了一个'命令已成功完成',因为从技术上来说它确实如此,但我的用户无法知道他们实际上没有更新任何内容。 是否有错误代码,返回代码,可以标记我向我的用户发送消息,让他们知道操作是成功的东西,但它没有更新任何东西,因为记录不存在?
I have a simple SQL update statement...
UPDATE [Table].[dbo].[Test] SET [Field1] = @Param1 WHERE [Field2] = @Param2
Let's say my data set is ONLY the following information...
Field 1 | Field 2 ------------------------- 123 | abc 456 | def 789 | ghi
My issue is as this... What if a user wants to update 'Field1' for 'def' to '444', but, oh no! They accidentally key 'dew' for 'Param2'. So this is our param set...
- Param1: 444
- Param2: dew
According to my testing I am getting a 'Command(s) completed successfully', because technically it did, but there is no way for my user to know that they didn't actually update anything. Is there an error code, return code, something that could flag me to send a message to my user letting them know the operation was a success, but it didn't update anything because the record didn't exist?
原文:https://stackoverflow.com/questions/22050091
最满意答案
如果您可以再次创建转储,则可以在转储时将
--insert-ignore
添加到命令行。或者您可以尝试使用带有
--force
的mysqlimport命令,即使遇到MySQL错误,该命令也会继续。If you can make the dump again you could add
--insert-ignore
to the command-line when dumping.Or you can try using the mysqlimport command with
--force
,which will continue even if it encounters MySQL Errors.
相关问答
更多-
如果您可以再次创建转储,则可以在转储时将--insert-ignore添加到命令行。 或者您可以尝试使用带有--force的mysqlimport命令,即使遇到MySQL错误,该命令也会继续。 If you can make the dump again you could add --insert-ignore to the command-line when dumping. Or you can try using the mysqlimport command with --force,which ...
-
有什么数据库专业书籍介绍?[2022-05-19]
mysql -
Dockerfile每个RUN指令都在不同的层中执行(如RUN文档中所述)。 您的Dockerfile有三条RUN指令。 问题是MySQL服务器只能在第一个启动。 在其他的,没有MySQL正在运行,这就是为什么你的mysql客户端连接错误。 要解决这个问题,你有2个解决方案。 解决方案1:使用单行RUN RUN /bin/bash -c "/usr/bin/mysqld_safe &" && \ sleep 5 && \ mysql -u root -e "CREATE DATABASE mydb" ...
-
对不起,在评论中你看不到刻度线 你可以使用1行shell脚本来完成它: line=`head -n 1 standardized.csv`; grep -v "$line" standardized.csv > new_standardized.csv 然后导入new_standardized,csv Sorry, in the comment you cant see the ticks You can do it with 1 line of shell script: line=`head -n ...
-
PHP - 导入MySQL数据库时跳过第一行csv(PHP - Skip the first row of csv when importing to MySQL Database)[2023-05-17]
工作会有一点变化。 在foreach循环之前split $csvcontent并将生成的数组安全地保存到$allLines 。 然后使用array_shift删除此数组的第一个元素(该函数也返回此元素,但我们不需要它): $allLines = split($lineseparator,$csvcontent); array_shift($allLines); // removes the 1st element foreach($allLines as $line) { [...] A lit ... -
好像我的数据库出了问题。 重新创建它解决了这个问题。 It seems that there was a problem with my database. Recreating it solved that problem.
-
不,你可能不会。 Oracle导出是一种专有的,未记录的文件格式。 实际上,它只能由Oracle导入实用程序读取。 可能有一些第三方工具可能反向设计了文件格式,但我不知道任何会导入MySQL的。 如果将数据导入本地Oracle数据库,则将其传输到MySQL数据库变得更加容易。 任何ETL工具都可以这样做,你可以编写一个应用程序来移动数据,你可以从Oracle连接到MySQL来推送数据,你可以从Oracle数据库中提取DDL和DML等。 No, you probably can't. An Oracle ex ...
-
导入mysql转储(Importing mysql dump)[2024-01-03]
尝试这样的事情: ... $dbhost = "blaa.mysql.eu1.frbit.com"; $dbuser = "dbusername"; $dbpass = 'mypasswordhere'; $dbname = "database_name"; $filename = "/var/www/blaa/sqlfilehere.sql" system("mysql -h $dbhost -u $dbuser --password='$dbpass' $dbname < $filename"); . ... -
我写了一个小的python脚本来转换它: LOCK TABLES `actor` WRITE; /*!40000 ALTER TABLE `actor` DISABLE KEYS */; INSERT INTO `actor` (`actor_id`, `first_name`, `last_name`, `last_update`) VALUES (1,'PENELOPE','GUINESS','2006-02-15 12:34:33'); INSERT INTO `actor` (`actor_id`, ...
-
导入MySQL 5.1.70转储期间MariaDB 10.0.16崩溃(MariaDB 10.0.16 crash during import of MySQL 5.1.70 dump)[2022-04-30]
看起来这可能是一个bug,也许与OpenBSD / PowerPC相关。 据MariaDB开发人员报道: http : //mariadb.atlassian.net/browse/MDEV-9569 It looks like this might be a bug, perhaps OpenBSD/PowerPC related. It has been reported to MariaDB developers here: http://mariadb.atlassian.net/browse/MD ...