msyql命令大全

1.創建數據庫

create database samp_db character set gbk;

2.創建數據庫

create table students
(
id int unsigned not null auto_increment primary key,
name char(30) not null,
sex char(4) not null,
age tinyint unsigned not null,
tel char(13) null default "-"
);

"id" 爲列的名稱;
"int" 指定該列的類型爲 int(取值範圍爲 -8388608到8388607), 在後面我們又用 "unsigned" 加以修
飾, 表示該類型爲無符號型, 此時該列的取值範圍爲 0到16777215;
"not null" 說明該列的值不能爲空, 必須要填, 如果不指定該屬性, 默認可爲空;
"auto_increment" 需在整數列中使用, 其作用是在插入數據時若該列爲 NULL, MySQL將自動產生一個比
現存值更大的唯一標識符值。在每張表中僅能有一個這樣的值且所在列必須爲索引列。
"primary key" 表示該列是表的主鍵, 本列的值必須唯一, MySQL將自動索引該列。

3.查詢表中數據

select * from students where sex="女"

4.向表中插入數據


5.更新表中數據

update students set tel=default where id=5;(default爲默認格式)

將所有人的年齡增加1: update students set age=age+1;

6.刪除表中數據

刪除id爲2的行: delete from students where id=2;
刪除表中的所有數據: delete from students;

7.在表中增加列

在表的最後追加列 address: alter table students add address char(60);
在名爲 age 的列後插入列 birthday: alter table students add birthday date after age;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章