CREATE TABLE table1 (
id INT PRIMARY KEY,
name VARCHAR(20),
);
CREATE TABLE table1 (
id INT,
name VARCHAR(20),
PRIMARY KEY(id),
);
Other Constraints: NOT NULL
,UNIQUE
,AUTO_INCREMENT
, DEFAULT 'sth'
.
DESCRIBE table1;
DROP TABLE table1;
ALTER TABLE table1 ADD discount DECIMAL(3,2);
3 digits, 2 decimal places.
ALTER TABLE table1 DROP COLUMN discount;
INSERT INTO table1 VALUES(1,'Jack');
INSERT INTO table1(id) VALUES(2);
INSERT INTO table1(name) VALUES('Leo'); #AUTO_INCREMENT
Notes: Cannot insert duplicate values.
UPDATE table1;
SET name = 'Kim' # SET VAL1 = val1, VAL2 = val2, ...
WHERE id = 2; # OR, AND
DELETE FROM table1
WHERE id=1 AND name='Leo';
SELECT * FROM table1;
SELECT id,name FROM table1;
SELECT table1.id,table1.name FROM table1;
ORDER BY name;
ORDER BY id,name ASC; # order by id, then by name
ORDER BY name DESC;
LIMIT 10;
WHERE id > 0 AND name = 'Jack';
WHERE id > 0 AND name <> 'Jack';
WHERE id > 0 AND name IN ('Jack','Leo');