[RUBY] Database operation (SQL)
Database operation ~ SQL ~
- Know how to use SQL
- Understand the basic operations of the database
- Understand the basic operation of tables
How to use in the terminal
Terminal
#Return to home directory
% cd
#Connect to MySQL
% mysql -u root
How to use with Sequel Pro
When logging in using Sequel Pro, enter the following
Execute the following SQL in the terminal
Terminal
mysql> CREATE DATABASE sqltest;
Execute the following SQL statement in MySQL
Terminal
mysql> SHOW DATABASES;
Delete database
Terminal
mysql> DROP DATABASE sqltest;
Specify database
Create a database and select
Terminal
mysql> CREATE DATABASE sqltest;
Query OK, 1 row affected (0.00 sec)
Create table with command
Terminal
mysql> CREATE TABLE goods (id INT, name VARCHAR(255));
View the created table
Terminal
mysql> SHOW TABLES;
Check the structure of the table
Terminal
mysql> SHOW columns FROM goods;
Add column
Terminal
mysql> ALTER TABLE goods ADD (price int, zaiko int);
Change column
Terminal
mysql> ALTER TABLE goods CHANGE zaiko stock int;
Delete column
Terminal
mysql> ALTER TABLE goods DROP stock;
That's all from the scene!