Thursday, December 11, 2008

Sore Stiff Throat,hard To Swallow

What are they and how to write select?

A database may contain a large amount of information, research and display of the most useful to the analysis of each, is made possible by some instructions, the SELECT statement.
We have already said what their basic syntax, Let's see more in particular:

SELECT * FROM table_name WHERE condition

• With the '* is required to extract all the fields. To get only those that most interest us enough to specify, in its place, the name of the fields. •
FROM gives the possibility to indicate the names of the tables from which to extrapolate the information. • WHERE
is a conditional expression, meaning that identify which records in the table must be searched.

Here's an example of SELECT:
A bank has at its disposal the chart of accounts of its customers, which account number, balance and the code has been assigned to each customer.



Suppose we want to have the list of customers that have a balance less than 0. Then ask: SELECT * FROM account WHERE balance < 0.
The result is:



The bank has also provided the CUSTOMER table, where there are data (name, ... tax code) to each customer, in this case, identified by a code.




If you want to have your account information is that the data of clients who have accounts in red, the DB may request them using the Join operator. This allows you to create relationships between two or more tables to extract data simultaneously present in them and link them with the key identifier in our case the codes of the customers. So we write the statement: SELECT * FROM account

INNER JOIN customer ON behalf. customer = customer code. WHERE customer number conto.saldo < 0.

The result is:



Without the WHERE clause, the table contains the personal information of all customers and their account information. Referring to tables

ACCOUNT CUSTOMERS, do the examples using the commands INSERT, UPDATE, DELETE.


INSERT The INSERT command is used to enter new values. Assuming that the bank wants to enter new data in the table ACCOUNTS in the "account number" and "balance", write: INSERT INTO

account (numero_conto, balance) VALUES (35.1200)


UPDATE: If a

customer has made a deposit will need to update your balance:

UPDATE account set balance = balance +200 WHERE numero_conto

= 35 With this statement we said to the database to increase the balance of 200 only to the account with account number 35.

DELETE :
If the bank wishes to cancel a customer from its database (for example, entered incorrectly) simply run: DELETE FROM customer WHERE
codice_cliente = 10

0 comments:

Post a Comment