深入淺出SQL

深入淺出SQL

啟動關聯式資料庫管理系統
(relation

終端機輸入這行進入SQL
mysql -h localhost -u root -p

輸入密碼

Enter password:

進入歡迎畫面
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 31
Server version: 5.7.12 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

建立資料庫

mysql> CREATE DATABASE gregs_list;  
Query OK, 1 row affected (0.01 sec)

使用資料庫

mysql> USE gregs_list;
Database changed


如果只有一個資料表是否還要資料庫?

A:所有資料表都要放在資料庫內,給予資料庫權限會比給予單一資料表權限來的簡單。


MySQL是否有大小寫區分?

A:不必,但指令與資料庫名稱分開大小寫可區分

CREATE DATABASE
gregs_list

命名資料庫有注意事項嗎?

A:避免大小寫混雜

‘的符號可以使用嗎?

A:在SQL內有特殊的使用


CREATE TABLE建立資料表
doughnut_list資料表名稱
doughnut_name資料欄名稱
doughnut_type資料欄名稱

VARCHAR 用以儲存可變字元(VARiable CHARacter)
意思是最多多長

mysql> CREATE TABLE doughnut_list
    -> (
    -> doughnut_name VARCHAR(10),
    -> doughnut_type VARCHAR(6)
    -> );
Query OK, 0 rows affected (0.02 sec)

刪除資料庫

DROP DATABASE database_name

Comments

Popular posts from this blog

MEGA 暫存檔案刪除

IOS GCD多執行緒

利用CMD指令強制刪除