mysql crud, php mysql, php, sql

19
MySQL CRUD in MySql By: Aimal Miakhel

Upload: aimal-khan

Post on 15-Jun-2015

497 views

Category:

Software


7 download

DESCRIPTION

Creating database whith mysql and php , Working with Crud

TRANSCRIPT

Page 1: Mysql Crud, Php Mysql, php, sql

MySQLCRUD in MySql

By: Aimal Miakhel

Page 2: Mysql Crud, Php Mysql, php, sql

Think of each table as a spreadsheet We define columns, also known as fields,

which classify our data Each record in the table is a row

Tables

Page 3: Mysql Crud, Php Mysql, php, sql

Varchar◦ Variable Characters, specify up to how many

characters something will be Char

◦ A set number of characters, good for things like state abbreviations

Int◦ Whole numbers, positive or negative

Data Types

Page 4: Mysql Crud, Php Mysql, php, sql

Float◦ Floating Point, also known as a decimal

Text◦ A huge blob of text, like a paragraph or more

TinyInt / Bit / Boolean◦ 0 or 1, True or False

DateTime◦ A date and time 0000-00-00 00:00:00

Data Types

Page 5: Mysql Crud, Php Mysql, php, sql

Depending on the flavor of SQL (Oracle, MySQL, MSSQL, PostgreSQL, etc) there are many more

Don’t get overwhelmed, just think of what will be best in terms of sorting and lookups

Data Types

Page 6: Mysql Crud, Php Mysql, php, sql

Creating Table in Mysql

CREATE TABLE User ( ID int, Username varchar(255), Password varchar(255) );

Create

Page 7: Mysql Crud, Php Mysql, php, sql

Username◦ Varchar

Password◦ Varchar

ID◦ Integer

AccountCreated◦ DateTime

User Table Example

Page 8: Mysql Crud, Php Mysql, php, sql

ID UserName

Password

1 John 123

2 Jane 334

3 Sally 567

4 Ryan 8675

5 Joe 908879

For example a user table

TableUser _

Page 9: Mysql Crud, Php Mysql, php, sql

Create Read Update Delete

CRUD

Page 10: Mysql Crud, Php Mysql, php, sql

INSERT is used to create a new record in the database

For example user is a table

INSERT into user VALUES (1,‘Aimal’, ‘Miakhel’);

Create

Page 11: Mysql Crud, Php Mysql, php, sql

SELECT is used to retrieve a record in the database

To select all the records from user table

SELECT * FROM user;

Retrieve

Page 12: Mysql Crud, Php Mysql, php, sql

Where is used for condition for some specific groups or records it filters the selection

Eg. SELECT username, password FROM users

WHERE ID = 1

Retrive with where command

Page 13: Mysql Crud, Php Mysql, php, sql

UPDATE is used to change record(s) in the database

UPDATE users SET username = ‘Ahmad’ WHERE ID = 1

Or UPDATE users SET username = ‘Ahmad’

WHERE username = ‘Aimal’

UPDATE

Page 14: Mysql Crud, Php Mysql, php, sql

DELETE is used to remove records from the database

DELETE FROM users WHERE ID = 1

** if you do not specify anything in the WHERE clause, it will delete everything in that table

DELETE

Page 15: Mysql Crud, Php Mysql, php, sql

SELECT User FROM Users WHERE ID IN (1,2)

SELECT * FROM UserWHERE Name IN (‘Ahmad',‘Ali');

IN

Page 16: Mysql Crud, Php Mysql, php, sql

SELECT User FROM Users WHERE ID BETWEEN 3 AND 5

SELECT * FROM UserWHERE ID BETWEEN 3 AND 5;

BETWEEN

Page 17: Mysql Crud, Php Mysql, php, sql

WHERE can also use wildcards for text◦ WHERE Column IS LIKE ‘%something%’

WHERE can use more than =◦ WHERE ID < 4◦ WHERE ID <= 4

WHERE can combine conditions◦ WHERE Column = ‘A’ AND Column2 = ‘B’◦ WHERE Column = ‘A’ OR Column2 = ‘B’◦ WHERE (Column = ‘A’ OR Column2 = B’) AND Other

= ‘C’

Conditions and Operators

Page 18: Mysql Crud, Php Mysql, php, sql

SQL has functions, like COUNT and SUM

SELECT Customer, SUM(Amount) FROM Orders GROUP BY Customer

SELECT COUNT(Customer) FROM Orders GROUP BY Customer

Nerding Out

Page 19: Mysql Crud, Php Mysql, php, sql

Design a database for university studentsContains Student registrationAttendanceFeesEtc

Date-03-09-2014

Assignment Database Design