2023年8月3日发(作者:)

SQLUPDATE语句和⽰例查询SQL databases provide structured data storage capabilities. We can store data in tables with columns and rows. Otheruseful features for SQL databases are update capabilities. We can update SQL database data in different ways andconstraints. In this tutorial, we will learn how to update database table data with an SQL UPDATE statement and query asingle record, multiple records, or conditional situations with 数据库提供结构化的数据存储功能。 我们可以将数据存储在具有列和⾏的表中。 SQL数据库的其他有⽤功能是更新功能。 我们可以采⽤不同的⽅式和约束来更新SQL数据库数据。 在本教程中,我们将学习如何使⽤SQL UPDATE语句更新数据库表数据以及如何通过⽰例查询单个记录,多个记录或条件情况。SQL UPDATE语法 (SQL UPDATE Syntax)SQL Update statement or query has the following syntax with the given Update语句或查询具有以下具有给定值的语法。update TABLE_NAMEset COLUMN1=VALUE1, COLUMN2=VALUE2, ... , COLUMNN=VALUENwhere CONDITION;TABLE_NAME is the table in which we want to update its _NAME是我们要在其中更新其记录的表。COLUMN1 is the column name we want to 1是我们要更新的列名。VALUE1 is the value we want to set the 1是我们要设置的值。 COLUMN and VALUE can be set for multiple times without a problem.可以多次设置COLUMN和VALUE 。CONDITION is used to select the record or row to ION⽤于选择要更新的记录或⾏。数据库表数据⽰例 (Example of Database Table Data)During this tutorial, we will use the following database table in order to update it in different ways. We try to make the tablesimple in order to prevent misunderstanding and decrease complexity. In this table, we have the following columns. Thetable is named Users.在本教程中,我们将使⽤以下数据库表以不同⽅式对其进⾏更新。 我们尝试使表格简单化,以防⽌误解并降低复杂性。 在此表中,我们具有以下列。 该表名为Users 。IDIDName名称City市Age年龄Country国家ID12345NameJoachim LöwAhmet Ali BaydanAntonio Moreno TaqueríaJames BondZlatan İbrahimovicCityBerlinAnkaraMéxicoLondonLuleaAge2035402560CountryGermanyTurkeyMexicoUKSwedenID1个2345名称约阿希姆·洛(JoachimLöw)艾哈迈德·阿⾥·拜丹(Ahmet Ali Baydan)安东尼奥·莫雷诺·塔克⾥亚占⼠邦Zlatanİbrahimovic市柏林安卡拉墨西哥伦敦露蕾亚年龄2035402560国家德国⽕鸡墨西哥英国瑞典更新表(Update Table)We will start with a simple update table example. We will only update the single record single value. We will update the agevalue of the Zlatan İbrahimovic by using its ID. We will set the age of the Zlatan İbrahimovic to the 38.我们将从⼀个简单的更新表⽰例开始。 我们将只更新单个记录单个值。 我们将使⽤其ID更新Zlatanİbrahimovic的年龄值。 我们将Zlatanİbrahimovic的年龄设定为38岁。UPDATE UsersSET Age=38WHERE ID=5;更新多个记录 (Update Multiple Records)Update records can be used to update multiple records in a single Update query execution. We have to specify someconditions which will match multiple records on the given table and update the given columns. In this example, we will theCountry of the users whose ages are over 30.更新记录可⽤于在单个Update查询执⾏中更新多个记录。 我们必须指定⼀些条件,这些条件将匹配给定表上的多个记录并更新给定的列。在此⽰例中,我们将选择年龄超过30岁的⽤户所在的国家/地区。UPDATE UsersSET Country='Turkey'WHERE Age>30;更新多列 (Update Multiple Columns)We can update multiple columns for the given condition. Here we need to specify the column and value pairs by delimitingthem with a comma. In this example, we will update the Country and City values of the users whose ages are over 30. Wewill set Country as Turkey and City as Ankara.我们可以针对给定条件更新多个列。 在这⾥,我们需要通过⽤逗号定界来指定列和值对。 在此⽰例中,我们将更新年龄超过30岁的⽤户的“国家/地区”和“城市”值。我们将“国家/地区”设置为“ Turkey ,将“城市”设置为“ Ankara 。UPDATE UsersSET Country='Turkey', City='Ankara'WHERE Age>30;更新特定列的所有表⾏/记录 (Update All Table Rows/Records For Specific Column)In some cases, we may need to update the whole table or all rows in a table for a specific column. In this case, we do notneed a condition because we will match all table rows. In this example, we will set all users table records Age value to the 30.在某些情况下,我们可能需要为特定列更新整个表或表中的所有⾏。 在这种情况下,我们不需要条件,因为我们将匹配所有表⾏。 在此⽰例中,我们将所有⽤户表记录的Age值设置为30 。UPDATE UsersSET Age=30;根据ID列更新 (Update According To ID Column)During the application development, we generally write some SQL queries. The update SQL query is one of the most usedones. Almost every application has some tables which have the ID column. We generally use ID values in order to update thetable. In this example, we will show how to update according to ID.在应⽤程序开发期间,我们通常会编写⼀些SQL查询。 更新SQL查询是最常⽤的查询之⼀。 ⼏乎每个应⽤程序都有⼀些带有ID列的表。 我们通常使⽤ID值来更新表。 在此⽰例中,我们将展⽰如何根据ID更新。UPDATE UsersSET Age=30WHERE ID=1;OR we can update records those ID numbers higher than 3 .或者,我们可以更新记录,这些ID编号⼤于3。UPDATE UsersSET Age=30WHERE ID>1;使⽤BETWEEN⼦句更新 (Update Using BETWEEN Clause)Another useful scenario for the SQL Update is using with a BETWEEN clause or condition to match records to be can specify range by using BETWEEN where the record values are between this range will be updated. In this example,we will update the Country to Turkey where Age is between 30 and Update的另⼀个有⽤⽅案是使⽤BETWEEN⼦句或条件来匹配要更新的记录。 我们可以使⽤BETWEEN来指定范围,其中记录值在此范围之间将被更新。 在此⽰例中,我们将国家/地区更新为年龄在30到40岁之间的⼟⽿其。UPDATE UsersSET Country='Turkey'WHERE Age BETWEEN 30 AND 40;使⽤SQL Select从其他表更新表 (Update Table From Other Table with SQL Select)Up to now we have updated data by providing explicitly and directly in a SQL query. In complex databases and applications,data can be provided from other tables. We can update data by fetching it from other tables by using the UPDATE SQLstatement. We will use an external table named Cities where we will update the Country value of the Users table recordsaccording to the Cities table.到⽬前为⽌,我们已经通过显式和直接在SQL查询中提供数据来更新数据。 在复杂的数据库和应⽤程序中,可以从其他表中提供数据。 我们可以通过使⽤UPDATE SQL语句从其他表中获取数据来更新数据。 我们将使⽤⼀个名为Cities的外部表,在该表中,我们将根据Cities表更新Users表记录的Country值。UPDATE UsersSET Country=(SELECT Country FROM Cities WHERE = )WHERE (SELECT Country FROM Cities WHERE =);使⽤SQL INNER JOIN更新 (Update Using SQL INNER JOIN)In the previous example, we have updated the Users table from another table named Cities. We can do this by using anINNER JOIN SQL statement. The scenario is the same as the previous example. We will use an external table named Citieswhere we will update the Country value of the Users table records according to the Cities table.在前⾯的⽰例中,我们从另⼀个名为Cities的表中更新了Users表。 我们可以使⽤INNER JOIN SQL语句来做到这⼀点。 该⽅案与前⾯的⽰例相同。 我们将使⽤⼀个名为Cities的外部表,在该表中,我们将根据Cities表更新Users表记录的Country值。UPDATE UsersSET y = yFROM UsersINNER JOIN CitiesON =;了解更多如何将PostgreSQL服务器安装到Linux,Debian,Ubuntu,CentOS,Mint,Fedora,Redhat中?

2023年8月3日发(作者:)

SQLUPDATE语句和⽰例查询SQL databases provide structured data storage capabilities. We can store data in tables with columns and rows. Otheruseful features for SQL databases are update capabilities. We can update SQL database data in different ways andconstraints. In this tutorial, we will learn how to update database table data with an SQL UPDATE statement and query asingle record, multiple records, or conditional situations with 数据库提供结构化的数据存储功能。 我们可以将数据存储在具有列和⾏的表中。 SQL数据库的其他有⽤功能是更新功能。 我们可以采⽤不同的⽅式和约束来更新SQL数据库数据。 在本教程中,我们将学习如何使⽤SQL UPDATE语句更新数据库表数据以及如何通过⽰例查询单个记录,多个记录或条件情况。SQL UPDATE语法 (SQL UPDATE Syntax)SQL Update statement or query has the following syntax with the given Update语句或查询具有以下具有给定值的语法。update TABLE_NAMEset COLUMN1=VALUE1, COLUMN2=VALUE2, ... , COLUMNN=VALUENwhere CONDITION;TABLE_NAME is the table in which we want to update its _NAME是我们要在其中更新其记录的表。COLUMN1 is the column name we want to 1是我们要更新的列名。VALUE1 is the value we want to set the 1是我们要设置的值。 COLUMN and VALUE can be set for multiple times without a problem.可以多次设置COLUMN和VALUE 。CONDITION is used to select the record or row to ION⽤于选择要更新的记录或⾏。数据库表数据⽰例 (Example of Database Table Data)During this tutorial, we will use the following database table in order to update it in different ways. We try to make the tablesimple in order to prevent misunderstanding and decrease complexity. In this table, we have the following columns. Thetable is named Users.在本教程中,我们将使⽤以下数据库表以不同⽅式对其进⾏更新。 我们尝试使表格简单化,以防⽌误解并降低复杂性。 在此表中,我们具有以下列。 该表名为Users 。IDIDName名称City市Age年龄Country国家ID12345NameJoachim LöwAhmet Ali BaydanAntonio Moreno TaqueríaJames BondZlatan İbrahimovicCityBerlinAnkaraMéxicoLondonLuleaAge2035402560CountryGermanyTurkeyMexicoUKSwedenID1个2345名称约阿希姆·洛(JoachimLöw)艾哈迈德·阿⾥·拜丹(Ahmet Ali Baydan)安东尼奥·莫雷诺·塔克⾥亚占⼠邦Zlatanİbrahimovic市柏林安卡拉墨西哥伦敦露蕾亚年龄2035402560国家德国⽕鸡墨西哥英国瑞典更新表(Update Table)We will start with a simple update table example. We will only update the single record single value. We will update the agevalue of the Zlatan İbrahimovic by using its ID. We will set the age of the Zlatan İbrahimovic to the 38.我们将从⼀个简单的更新表⽰例开始。 我们将只更新单个记录单个值。 我们将使⽤其ID更新Zlatanİbrahimovic的年龄值。 我们将Zlatanİbrahimovic的年龄设定为38岁。UPDATE UsersSET Age=38WHERE ID=5;更新多个记录 (Update Multiple Records)Update records can be used to update multiple records in a single Update query execution. We have to specify someconditions which will match multiple records on the given table and update the given columns. In this example, we will theCountry of the users whose ages are over 30.更新记录可⽤于在单个Update查询执⾏中更新多个记录。 我们必须指定⼀些条件,这些条件将匹配给定表上的多个记录并更新给定的列。在此⽰例中,我们将选择年龄超过30岁的⽤户所在的国家/地区。UPDATE UsersSET Country='Turkey'WHERE Age>30;更新多列 (Update Multiple Columns)We can update multiple columns for the given condition. Here we need to specify the column and value pairs by delimitingthem with a comma. In this example, we will update the Country and City values of the users whose ages are over 30. Wewill set Country as Turkey and City as Ankara.我们可以针对给定条件更新多个列。 在这⾥,我们需要通过⽤逗号定界来指定列和值对。 在此⽰例中,我们将更新年龄超过30岁的⽤户的“国家/地区”和“城市”值。我们将“国家/地区”设置为“ Turkey ,将“城市”设置为“ Ankara 。UPDATE UsersSET Country='Turkey', City='Ankara'WHERE Age>30;更新特定列的所有表⾏/记录 (Update All Table Rows/Records For Specific Column)In some cases, we may need to update the whole table or all rows in a table for a specific column. In this case, we do notneed a condition because we will match all table rows. In this example, we will set all users table records Age value to the 30.在某些情况下,我们可能需要为特定列更新整个表或表中的所有⾏。 在这种情况下,我们不需要条件,因为我们将匹配所有表⾏。 在此⽰例中,我们将所有⽤户表记录的Age值设置为30 。UPDATE UsersSET Age=30;根据ID列更新 (Update According To ID Column)During the application development, we generally write some SQL queries. The update SQL query is one of the most usedones. Almost every application has some tables which have the ID column. We generally use ID values in order to update thetable. In this example, we will show how to update according to ID.在应⽤程序开发期间,我们通常会编写⼀些SQL查询。 更新SQL查询是最常⽤的查询之⼀。 ⼏乎每个应⽤程序都有⼀些带有ID列的表。 我们通常使⽤ID值来更新表。 在此⽰例中,我们将展⽰如何根据ID更新。UPDATE UsersSET Age=30WHERE ID=1;OR we can update records those ID numbers higher than 3 .或者,我们可以更新记录,这些ID编号⼤于3。UPDATE UsersSET Age=30WHERE ID>1;使⽤BETWEEN⼦句更新 (Update Using BETWEEN Clause)Another useful scenario for the SQL Update is using with a BETWEEN clause or condition to match records to be can specify range by using BETWEEN where the record values are between this range will be updated. In this example,we will update the Country to Turkey where Age is between 30 and Update的另⼀个有⽤⽅案是使⽤BETWEEN⼦句或条件来匹配要更新的记录。 我们可以使⽤BETWEEN来指定范围,其中记录值在此范围之间将被更新。 在此⽰例中,我们将国家/地区更新为年龄在30到40岁之间的⼟⽿其。UPDATE UsersSET Country='Turkey'WHERE Age BETWEEN 30 AND 40;使⽤SQL Select从其他表更新表 (Update Table From Other Table with SQL Select)Up to now we have updated data by providing explicitly and directly in a SQL query. In complex databases and applications,data can be provided from other tables. We can update data by fetching it from other tables by using the UPDATE SQLstatement. We will use an external table named Cities where we will update the Country value of the Users table recordsaccording to the Cities table.到⽬前为⽌,我们已经通过显式和直接在SQL查询中提供数据来更新数据。 在复杂的数据库和应⽤程序中,可以从其他表中提供数据。 我们可以通过使⽤UPDATE SQL语句从其他表中获取数据来更新数据。 我们将使⽤⼀个名为Cities的外部表,在该表中,我们将根据Cities表更新Users表记录的Country值。UPDATE UsersSET Country=(SELECT Country FROM Cities WHERE = )WHERE (SELECT Country FROM Cities WHERE =);使⽤SQL INNER JOIN更新 (Update Using SQL INNER JOIN)In the previous example, we have updated the Users table from another table named Cities. We can do this by using anINNER JOIN SQL statement. The scenario is the same as the previous example. We will use an external table named Citieswhere we will update the Country value of the Users table records according to the Cities table.在前⾯的⽰例中,我们从另⼀个名为Cities的表中更新了Users表。 我们可以使⽤INNER JOIN SQL语句来做到这⼀点。 该⽅案与前⾯的⽰例相同。 我们将使⽤⼀个名为Cities的外部表,在该表中,我们将根据Cities表更新Users表记录的Country值。UPDATE UsersSET y = yFROM UsersINNER JOIN CitiesON =;了解更多如何将PostgreSQL服务器安装到Linux,Debian,Ubuntu,CentOS,Mint,Fedora,Redhat中?