-- print store location show variables like'%datadir%';
-- print database in stoarage SHOW DATABASES;
-- Create a new database CREATE DATABASE `sql_invoicing`; -- Access the database USE `sql_invoicing`;
-- Create a table CREATETABLE runoob_tbl( runoob_id INTNOTNULL AUTO_INCREMENT, runoob_title VARCHAR(100) NOTNULL, runoob_author VARCHAR(40) NOTNULL, submission_date DATE, PRIMARY KEY ( runoob_id ) )ENGINE=InnoDB DEFAULT CHARSET=utf8; -- show tables SHOW TABLES
-- Check the index desc runoob_tbl
/* INT: datatype = integer; DATE: datatype = date; NOT NULL: value auto-fill; AUTO_INCREMENT: fill-logic; VARCHAR(10): ??? I don't know */ -- Insert value to table INSERTINTO runoob_tbl (runoob_title, runoob_author, submission_date) VALUES ("学习 PHP", "菜鸟教程", NOW());
-- Insert multi-lines value to table INSERTINTO runoob_tbl (runoob_title, runoob_author, submission_date) VALUES ("学习 myspl", "karobben", NOW()), ('learn python', 'Karobben', NOW());
-- Print the whole table SELECT*from runoob_tbl; -- Print the `runoob_title` column(field) SELECT `runoob_title` from runoob_tbl; -- Print the filtered result by WHEN SELECT*from runoob_tbl WHERE runoob_author='karobben'; #Capitals letters tolerant SELECT*from runoob_tbl WHEREBINARY runoob_author='Karobben'; #Capital letter matters -- Print the filtered result by LIKE SELECT*from runoob_tbl WHERE runoob_author LIKE'%rob%';
-- Change the value of tables by update UPDATE runoob_tbl SET runoob_title='sleep'WHERE runoob_id=3; -- Change a part of string in column(field) UPDATE runoob_tbl SET runoob_author=REPLACE(runoob_author, 'ka', 'Ka') -- Change the value of table by delete DELETEFROM runoob_tbl WHERE runoob_id=1;
-- delete the tale DROPTABLE `runoob_tbl`; -- delete the database DROP DATABASE `sql_invoicing`
-- match the column which end with a| grep a$ '%a' -- match the column which start with a| grep ^a 'a%' -- match the column which contain a| grep a '%a%' -- match pattern: grep ^.a.$ '_a_' -- match pattern: grep ^.a$ '_a' -- match pattern: grep ^a$ 'a_'
SELECT*from runoob_tbl WHERE runoob_title LIKE'% %';
UPDATE runoob_tbl SET runoob_title='学习 C++'WHERE runoob_id=3; DELETEFROM runoob_tbl WHERE runoob_id=3;
UNION
So, union could combine the unique values from different selected columns to a new table sql SELECT runoob_title FROM runoob_tbl UNION SELECT runoob_author FROM runoob_tbl;