Wikibooks: Database Design/SQL Data Manipulation Language
The SQL data manipulation language (DML) is used to query and modify database data. In this chapter we will describe how to use the SELECT INSERT UPDATE and DELETE SQL DML command statements defined below. SELECT – to query data in the database INSERT – to insert data into a table UPDATE – to up...
Format: | Book |
---|---|
Language: | English |
Subjects: | |
Online Access: | https://en.wikibooks.org/wiki/Database_Design/SQL_Data_Manipulation_Language |
Summary: | The SQL data manipulation language (DML) is used to query and modify database data. In this chapter we will describe how to use the SELECT INSERT UPDATE and DELETE SQL DML command statements defined below. SELECT – to query data in the database INSERT – to insert data into a table UPDATE – to update data in a table DELETE – to delete data from a table In the SQL DML statement Each clause in a statement should begin on a new line. The beginning of each clause should line up with the beginning of other clauses. If a clause has several parts they should appear on separate lines and be indented under the start of the clause to show the relationship. Upper case letters are used to represent reserved words. Lower case letters are used to represent user defined words. = SELECT Statement = The SELECT statement or command allows the user to extract data from tables based on specific criteria. It is processed according to the following sequence SELECT DISTINCT item(s) FROM table(s) WHERE predicate GROUP BY field(s) ORDER BY fields We can use the SELECT statement to generate an employee phone list from the Employees table as follows SELECT FirstName LastName phone FROM Employees ORDER BY LastName This action will display employee’s last name first name and phone number from the Employees table seen in Table 16.1. Table 16.1. Employees table. In this next example we will use a Publishers table (Table 16.2). (You will notice that Canada is misspelled in the Publisher Country field for Example Publishing and ABC Publishing. To correct mispelling use the UPDATE statement to standardize the country field to Canada – see UPDATE statement later in this chapter.) Table 16.2. Publishers table. If you add the publisher’s name and city you would use the SELECT statement followed by the fields name separated by a comma SELECT PubName city FROM Publishers This action will display the publisher’s name and city from the Publishers table. If you just want the publisher’s name under the display name city you ... |
---|