CRUD in MySql 
By: Aimal Miakhel
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
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
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
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
Creating Table in Mysql 
CREATE TABLE User 
( 
ID int, 
Username varchar(255), 
Password varchar(255) 
);
Username 
◦ Varchar 
Password 
◦ Varchar 
ID 
◦ Integer 
AccountCreated 
◦ DateTime
ID UserNa 
me 
Passwo 
rd 
1 John 123 
2 Jane 334 
3 Sally 567 
4 Ryan 8675 
5 Joe 90887 
9 
User _Table
Create 
Read 
Update 
Delete
INSERT is used to create a new record in the 
database 
For example user is a table 
INSERT into user VALUES (1,‘Aimal’, 
‘Miakhel’);
SELECT is used to retrieve a record in the 
database 
To select all the records from user table 
SELECT * FROM user;
Where is used for condition for some specific 
groups or records it filters the selection 
Eg. 
SELECT username, password FROM users 
WHERE ID = 1
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’
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
SELECT User FROM Users WHERE ID IN (1,2) 
SELECT * FROM User 
WHERE Name IN (‘Ahmad',‘Ali');
SELECT User FROM Users WHERE ID BETWEEN 
3 AND 5 
SELECT * FROM User 
WHERE ID BETWEEN 3 AND 5;
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’
SQL has functions, like COUNT and SUM 
SELECT Customer, SUM(Amount) FROM 
Orders GROUP BY Customer 
SELECT COUNT(Customer) FROM Orders 
GROUP BY Customer
Design a database for university students 
Contains 
Student registration 
Attendance 
Fees 
Etc 
Date-03-09-2014

Mysql Crud, Php Mysql, php, sql

  • 1.
    CRUD in MySql By: Aimal Miakhel
  • 2.
    Think of eachtable as a spreadsheet We define columns, also known as fields, which classify our data Each record in the table is a row
  • 3.
    Varchar ◦ VariableCharacters, 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
  • 4.
    Float ◦ FloatingPoint, 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
  • 5.
    Depending on theflavor 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
  • 6.
    Creating Table inMysql CREATE TABLE User ( ID int, Username varchar(255), Password varchar(255) );
  • 7.
    Username ◦ Varchar Password ◦ Varchar ID ◦ Integer AccountCreated ◦ DateTime
  • 8.
    ID UserNa me Passwo rd 1 John 123 2 Jane 334 3 Sally 567 4 Ryan 8675 5 Joe 90887 9 User _Table
  • 9.
  • 10.
    INSERT is usedto create a new record in the database For example user is a table INSERT into user VALUES (1,‘Aimal’, ‘Miakhel’);
  • 11.
    SELECT is usedto retrieve a record in the database To select all the records from user table SELECT * FROM user;
  • 12.
    Where is usedfor condition for some specific groups or records it filters the selection Eg. SELECT username, password FROM users WHERE ID = 1
  • 13.
    UPDATE is usedto change record(s) in the database UPDATE users SET username = ‘Ahmad’ WHERE ID = 1 Or UPDATE users SET username = ‘Ahmad’ WHERE username = ‘Aimal’
  • 14.
    DELETE is usedto 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
  • 15.
    SELECT User FROMUsers WHERE ID IN (1,2) SELECT * FROM User WHERE Name IN (‘Ahmad',‘Ali');
  • 16.
    SELECT User FROMUsers WHERE ID BETWEEN 3 AND 5 SELECT * FROM User WHERE ID BETWEEN 3 AND 5;
  • 17.
    WHERE can alsouse 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’
  • 18.
    SQL has functions,like COUNT and SUM SELECT Customer, SUM(Amount) FROM Orders GROUP BY Customer SELECT COUNT(Customer) FROM Orders GROUP BY Customer
  • 19.
    Design a databasefor university students Contains Student registration Attendance Fees Etc Date-03-09-2014