![]() ![]() WHERE id = 7 RETURNING * Code language: SQL (Structured Query Language) ( sql ) The following statement deletes the row with id 7 and returns the deleted row to the client: DELETE FROM links Since the row with id 10 does not exist, the statement returns 0: DELETE 0 Code language: Shell Session ( shell ) 2) Using PostgreSQL DELETE to delete a row and return the deleted row WHERE id = 10 Code language: SQL (Structured Query Language) ( sql ) The following statement uses the DELETE statement to delete the row with id 10: DELETE FROM links The statement returns 1 indicated that one row has been deleted: DELETE 1 Code language: Shell Session ( shell ) ![]() WHERE id = 8 Code language: SQL (Structured Query Language) ( sql ) The following statement uses the DELETE statement to delete one row with the id 8 from the links table: DELETE FROM links Here are the contents of the links table: SELECT * FROM links Code language: SQL (Structured Query Language) ( sql ) 1) Using PostgreSQL DELETE to delete one row from the table ( '8', '', 'PostgreSQL', 'PostgreSQL', 'nofollow', '') Code language: SQL (Structured Query Language) ( sql ) ( '1', '', 'PostgreSQL Tutorial', 'Learn PostgreSQL fast and easy', 'follow', ''), The following statements create a new table called links and insert some sample data: DROP TABLE IF EXISTS links Let’s set up a sample table for the demonstration. If you want to change the structure of a table such as removing a column, you should use the ALTER TABLE statement. It doesn’t modify the structure of the table. Note that the DELETE statement only removes data from a table. To return specific columns, you specify them after the RETURNING keyword. The asterisk ( *) allows you to return all columns of the deleted row from the table_name. RETURNING (select_list | *) Code language: SQL (Structured Query Language) ( sql ) To return the deleted row(s) to the client, you use the RETURNING clause as follows: DELETE FROM table_name It returns zero if the DELETE statement did not delete any row. The DELETE statement returns the number of rows deleted. If you omit the WHERE clause, the DELETE statement will delete all rows in the table.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |