Your SlideShare is downloading. ×

Web app development_my_sql_09

309

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
309
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
22
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. hasen@microcis.net July 16, 2013Hassen poreya Trainer, Cresco Solution Afghanistan Workforce Development Program Database MySQL, Modification Commands
  • 2. Modification Commands  There are three SQL commands to modify the database:  INSERT  DELETE  UPDATE
  • 3. INSERT Command  In its simplest form, it is used to add one or more tuples to a relation.  Tuples are the rows  Relations are the tables.  Attribute values should be listed in the same order as the attributes were specified in the CREATE TABLE command.
  • 4. INSERT Command INSERT INTO table name VALUES (value1, value2, ...);  Values are separated by comma ,  Strings, Dates are enclosed by single quotation marks ‘’  Values have to be sorted according to the table structure (the columns)
  • 5. INSERT Command INSERT INTO employee VALUES (1,'John',‘ Smith', 'Berlin', '1979- 09-04', 1000.40); INSERT INTO project VALUES (1, 'Database Design', 'Kabul'); INSERT INTO works in VALUES(1,1,40);
  • 6. INSERT Command INSERT INTO employee VALUES (NULL, 'Anna', 'Conner', 'London', '1960-11-10‘,1.40); What will happen if we put null value in the id field?
  • 7. INSERT Command  If we used AUTO INCREMENT for the definition of a column, the database system will automatically compute a unique value for Id.  The value is computed by incrementing the maximum value for Id already in the database.
  • 8. DELETE Command  Removes tuples from a relation.  Includes a WHERE clause to select the tuples to be deleted.  A missing WHERE clause species that all tuples in the relation are to be deleted; the table then becomes an empty table.  The number of tuples deleted depends on the number of tuples in the relation that satisfy the WHERE clause.
  • 9. DELETE Command DELETE FROM table name WHERE condition; DELETE FROM employee WHERE id=1; DELETE FROM project WHERE location=‘kabul’;
  • 10. INSERT Command: Integrity Constraints  Integrity Constraints:  One of the tasks of a database system is to make (automatically) sure that the stored data is in a consistent state.  When we model the Mini-World we also model what a consistent state means for us by defining integrity constraints.  In our company each employee is assigned a unique id as the PRIMARY KEY
  • 11. Integrity Constraints: PRIMARY KEY  Primary Key  Database system automatically rejects all new records with a key that is already stored in the database as below:
  • 12. Integrity Constraints: UNIQUE  UNIQUE  Similar to primary key: has to be unique  We do not want to use name as a primary key to identify records, but still we want to express that it has to be unique.
  • 13. Integrity Constraints: NOT NULL  NOT NULL  Sometimes we want to make sure that a value is always assigned to a column, so we use NOT NULL  Primary keys are automatically defined as NOT NULL (we couldn't identify an employee if there is no Id stored)
  • 14. Modification Command: UPDATE  It is used to modify attribute values of one or more selected tuples.  A WHERE clause selects the tuples to be modified.  An additional SET clause species the attributes to be modified and their new values.
  • 15. Modification Command: SELECT  Extract data stored in some columns of some table.  General syntax is: SELECT column name1, column name2, ... FROM table name; SELECT * FROM table name;  The asterisk (*) retrieves all attributes form the specified table.
  • 16. Modification Command: SELECT SELECT last name, location, salary FROM employee
  • 17. Modification Command: SELECT SELECT * FROM employee
  • 18. SELECT Command: WHERE  Basic form of the SQL SELECT statement is called a mapping or a SELECT-FROM-WHERE- block. SELECT < attributelist > FROM < tablelist > WHERE < condition >  < condition > is a conditional (Boolean) expression that identifies the tuples to be retrieved by the query.
  • 19. SELECT Command: WHERE SELECT location, salary FROM employee WHERE last_name=Smith;
  • 20. SELECT Command: ORDER BY  Sort the result according to some column, descending or ascending.
  • 21. SELECT Command: ORDER BY  Compare the result with the same query using ORDER BY.
  • 22. Let’s do something
  • 23. hasen@microcis.net July 16, 2013Hassen poreya Trainer, Cresco Solution Any Questions!

×