DB mysql Basic Query - CREATE(DB, Table), Add(Column), Delete(DB, Table, Column)
OS : Ubuntu
Start mysql
- sudo mysql
Shows the current DB
- SHOW DATABASES;
Create DataBase
-> CREATE DATABASE [DB name];
Use the DB
-> USE [DB name];
Create Table
-> CREATE TABLE [Table name](
[column name] INT NOT NULL AUTO_INCREMENT, -> id is primary number
[column name] VARCHAR(255) NOT NULL,
PRIMARY KEY([column name])
);
INT : integer number
NOT NULL : Not allow null
AUTO_INCREMENT : id number will increase automatically
VARCHAR : You could type string
PRIMARY KEY([column name]) : Assign a Primary key
Show tables
-> SHOW TABLES;
Add column in the existed table
-> ALTER TABLE [table name]
ADD COLUMN [column name] INT AFTER [existed column name]; -> 'age' is what you want to add
ALTER TABLE [table name] : Update table
ADD COLUMN : Add column
AFTER name : column 'name' is already existed. So 'age' column will add next to the 'name'.
Show columns
-> SHOW COLUMNS FROM [Table name];
Delete Table Column
-> ALTER TABLE [table name]
DROP COLUMN [column you want to delete];
댓글
댓글 쓰기