This SQL Server instructional exercise discloses how to utilize the UPDATE proclamation in SQL Server (Transact-SQL) with sentence structure and cases.
Depiction
The SQL Server (Transact-SQL) UPDATE proclamation is utilized to refresh existing records in a table in a SQL Server database. There are 3 sentence structures for the UPDATE proclamation relying upon whether you are playing out a conventional refresh or refreshing one table with information from another table.
Sentence structure
The sentence structure for the UPDATE articulation when refreshing one table in SQL Server (Transact-SQL) is:
Refresh table
SET column1 = expression1,
column2 = expression2,
...
[WHERE conditions];
Or then again
The grammar for the UPDATE articulation when refreshing one table with information from another table in SQL Server (Transact-SQL) is:
Refresh table1
SET column1 = (SELECT expression1
FROM table2
WHERE conditions)
[WHERE conditions];
Or then again
The language structure for the SQL Server UPDATE articulation when refreshing one table with information from another table is:
Refresh table1
SET table1.column = table2.expression1
FROM table1
Internal JOIN table2
ON (table1.column1 = table2.column1)
[WHERE conditions];
Parameters or Arguments
column1, column2
The sections that you wish to refresh.
expression1, expression2
The new esteems to dole out to the column1, column2. So column1 would be alloted the estimation of expression1, column2 would be allocated the estimation of expression2, et cetera.
WHERE conditions
Discretionary. The conditions that must be met for the refresh to execute.
Case - Update single segment
How about we take a gander at an exceptionally straightforward SQL Server UPDATE question case.
For instance:
Refresh representatives
SET last_name = 'Johnson'
WHERE employee_id = 10;
This SQL Server UPDATE illustration would refresh the last_name to 'Johnson' in the workers table where the employee_id is 10.
Illustration - Update various sections
How about we take a gander at a SQL Server UPDATE case where you should need to refresh in excess of one section with a solitary UPDATE proclamation.
For instance:
Refresh representatives
SET first_name = 'Kyle',
employee_id = 14
WHERE last_name = 'Johnson';
When you wish to refresh various sections, you can do this by isolating the segment/esteem sets with commas.
This SQL Server UPDATE articulation case would refresh the first_name to 'Kyle' and the employee_id to 14 where the last_name is 'Johnson'.
Illustration - Update table with information from another table
How about we take a gander at an UPDATE illustration that demonstrates to refresh a table with information from another table in MySQL.
For instance:
Refresh representatives
SET first_name = (SELECT first_name
FROM contacts
WHERE contacts.last_name = employees.last_name)
WHERE employee_id > 95;
This UPDATE illustration would refresh just the workers table for all records where the employee_id is more noteworthy than 95. At the point when the last_name from the contacts table matches the last_name from the representatives table, the first_name from the contacts table would be replicated to the first_name field in the workers table.
You could change this UPDATE explanation in SQL Server utilizing the second language structure to refresh a table with information from another table.
For instance:
Refresh representatives
SET employees.first_name = contacts.first_name
FROM workers
Internal JOIN contacts
ON (employees.last_name = contacts.last_name)
WHERE employee_id > 95;
This UPDATE case would play out an indistinguishable refresh from the past.

0 comentários:
Postar um comentário