建表的三正規化原則
1nf:字段不可拆分
,必須有主鍵
2nf:不是復合主鍵
,所有非主鍵欄位都由主鍵決定
3nf:是復合主鍵
,所有非主鍵欄位都由復合主鍵共同決定
,不能部分決定
#表示備註 這裡的命令大小寫都可以。
#建立資料庫
create database name
#刪除資料庫
drop database name
#使用資料庫 之後建立表都預設為資料該資料庫
use name
備註:表項 columns 表型別
value
表屬性storage (字段)
#刪除表表
drop table name
#建立表
create table t_class( class_id varchar(50) primary key,
class_name varchar(50) );
表項表型別
表屬性,逗號表示一項結束
開始下一項。
所有項新增完成,後面可以新增特殊說明
外來鍵特殊按說明
foreign key (自己表項
) references
外來鍵表名
(外來鍵表項
)新增表項
alter table 表名
add
表項 表型別 表屬性
顯示所有表
顯示表建立方法
show create table 表名
分欄介面顯示表
show columns from 表名
顯示資料庫
#資料插入
insert 刪除
delete
更新 update
查詢 select
如果表項不寫
,預設為所有表項,如果預設,其他值預設為空
insert into 表名 (表項
1, 表項二
) values(
內容1,
內容二);
delete from 表名
where
主鍵表項
= 表項的內容(值);列如
:delete from t_class where class_id = 'cr002';
修改表項中的值
update 表名 要改表項
1=要改表值
1, 要改表項
2 =要改表值
2 where
主鍵表項
= 表項的內容(值);查詢
條件查詢,檢視其中幾項表
select 表項
1,表項
2 from
表名;
條件查詢,檢視表名的所有表項
select * from 表名
;
select * from t_class;
條件查詢,檢視表名的所有表項
select * from 表名
where
條件語句
; 可以查表項等於某個值 也可以判斷大小
select * from t_class where class_id = 'cr001' and class_name = '科銳2班
';select * from t_class where class_id >= 'cr001';
select * from t_class where class_id <> 'cr001';
mysql 的基本語法 MYSQL基本語法
資料庫 可視為電子化的檔案櫃 儲存電子檔案的處所 為什麼使用資料庫 持久化 方便管理資料 結構化查詢 非結構化查詢 net start 程式 啟動 net stop 程式 結束 mysql uroot p3307 p 新建資料庫 create database 資料庫名 使用資料庫 use 資料庫名...
mysql的基本語法 mysql的基本語法
正文本篇文章主要是記錄一些常用的mysql語法,方便使用時候進行查閱。linux上常用命令 命令都以 結尾 1,登入mysql mysql u賬號 p密碼 2,檢視幫助 help 或者 h 3,檢視有哪些資料庫 show databases 4,進入某個資料庫 use databasename 5,...
MySql基本語法
基本語法 create database 資料庫名 資料庫選項 字符集等 基本語法 匹配模式 show create database 資料庫名 use 資料庫名 修改庫選項 alter database 資料庫名 選項 值 基本語法 drop 資料庫名 基本語法 create table 表名 欄...