Uploaded by evansjunephp

MySQL Data Manipulation

advertisement
Data Manipulation
Insert, Update, Delete
Inserting Data

Data insertion can be done in mainly 2 ways:
 Inserting
new data into a table
 Inserting
into all fields of a table
 Inserting into some fields of a table
 Inserting
 Inserting
data from another table into a table.
data from another table without any manipulation
 Inserting data from another table after manipulation
…

Inserting new data: All fields
 General
syntax:
 INSERT
INTO table_name VALUES
(column_1_value,column_2_value,…,column_n_value);
 NB:
 The
order of values MUST be the same as the order of the
columns of the table.
…

Example:
 Consider
the customer table with columns:
 Customer(CustomerID,customerName,
mobilenumber, email, birthdate,
customer_hobbies, best_dish)
 INSERT
INTO customer VALUES (NULL,’Mustafa
Ali’,’00222228’,’musta@gmail.com’,’2001-1030’,’Reading,Programming’,’Bananas’);
….

INSERT INTO
supplier(supplierName,mobileNumber,phy
sicaladdress) VALUES (‘Mukwano
Industries’,’256702352258’,’Railway
Station’)
Task
 Insert
the following data into the employee table
EmployeeID
EmployeeName
1
Kato Hussein 25670
16588
55
Adam Sebbit 25674
15855
52
Okello
Joseph
Adunga
Juma
2
3
4
mobileN basicsalary
umber
250000
Employee_s
port
Employee_
medals
Hockey
2
Rugby
1
300000
200000
100000
…


Create a table for GolfClubMember with the
following fields:
GOLFCLUBMEMBER
 MemberID
[auto generated]
 Membername
 Membermobile [Optional]
 ExpiryDate [Optional]
INSERT from another TABLE


Insert data from table
General Syntax:


INSERT INTO table_name(column_1,column_2) SELECT
column_1,column_2 FROM source_table;
Example:
Consider inserting data from the employee table into the
GolfClubmember table:
 INSERT INTO
golfclubmember(membername,membermobile) SELECT
employeename,mobilenumber FROM employee;

Download