05-05 08:32
Notice
Recent Posts
Recent Comments
관리 메뉴

Scientific Computing & Data Science

Frequently Used MySQL Quries 본문

Data Science/MySQL

Frequently Used MySQL Quries

cinema4dr12 2014. 1. 5. 22:53

SHOW DATABASES;
// print the current list of database


USE test;
// select the database "test"


CREATE DATABASE test;
// create a database named "test"


CREATE TABLE mytable(
    id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(25) NOT NULL,
    content VARCHAR(255) NOT NULL
);

// create a table named "mytable" with the fields of id, name and content


DESC mytable;
// print out the structure of mytable


INSERT INTO mytable (name, content) VALUES( 'gchoi', 'MySQL' );
// add 'gchoi' into name field and 'MySQL' into content field of mytable


SELECT * FROM mytable;
// inquiry data from mytable


SELECT id, name FROM mytable;
// inquiry only id and name field from mytable


SELECT * FROM mytable WHERE name='gchoi';
// inquiry data of name with 'gchoi'


SELECT * FROM mytable WHERE name LIKE 'gc%';
// inquiry all data from mytable


SELECT * FROM mytable WHERE name LIKE 'gc__';
// inquiry all data from mytable


SELECT * FROM mytable ORDER BY id;
// print the current list of database


SELECT * FROM mytable ORDER BY id ASC;
// print the current list of database


SELECT * FROM mytable ORDER BY id DESC;
// print the current list of database


SELECT * FROM mytable LIMIT 2;
// print the current list of database


SELECT * FROM mytable LIMIT 2, 2;
// print the current list of database


SELECT * FROM mytalbe WHERE (id < 3) AND (name LIKE 'gc%') ORDER BY id ASC LIMIT 4;
// print the current list of database


UPDATE mytable SET name = 'cinema4d' WHERE id = 5;
// update table content of id 5: name 'cinema4d'


UPDATE mytable SET name = 'cinema4d', content = 'Node.js' WHERE id = 5;
// update table content of id 5: name 'cinema4d' / content 'Node.js'


DELETE FROM mytable WHERE id = 5;
// delete id number 5 from mytable


DROP TABLE mytable;
// delete a table of the name 'mytable'


DROP DATABASE test;
// delete a database of the name 'test'

'Data Science > MySQL' 카테고리의 다른 글

Execute MySQL Console on Mac  (0) 2014.01.05
Comments