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];



Delete DB
-> DROP DATABASE [DB name];


Warning: If you delete the DB, the data will also be deleted.

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];




Next Link





댓글

이 블로그의 인기 게시물

Lesson 12_1 프로퍼티 노드(Property Node)

DAQ로 전압 측정하기-2

Lesson 12_2 참조를 이용한 프로퍼티노드(Property Node)