SQL Statements
Manipulating tables and data in a MySQL database is acheived with the language called SQL (Structered Query Language).
Tables
Tables can be created using the CREATE TABLE statement.
CREATE TABLE products (
id INT NOT NULL PRIMARY KEY,
name VARCHAR(30),
price DECIMAL(6,2),
stock INT
)
|
To remove a table, you would use the DROP TABLE statement.
Data
Data is added to a table with the INSERT statement.
INSERT INTO products (id, name, price, stock) VALUES (101, "widget", 4.75, 10)
|
Data can be modified with the UPDATE statement.
INSERT products SET price = 4.99 WHERE id = 101
|
To delete data, use the DELETE statement.
DELETE FROM products WHERE id = 101
|
Finally, data can be retreived using the SELECT statement.
SELECT name, price, stock FROM products WHERE id = 101
|
<-- Previous Next -->
|