MySQL 基礎操作表操作(一)

MySQL

  建庫:

   create database 庫名::如create database student;

 建表案例:

CREATE TABLE `staff` (
  `id` int(6) NOT NULL AUTO_INCREMENT,
  `name` char(25)  NOT NULL,
  `sex` int(2) NOT NULL,
  `age` int(3) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; 

注意:

  engine::表的搜索引擎;

  charset::設置表的字符集;

  primary key ():設置表的主鍵:

  auto_increment:設置自增字段 ;

字段設計簡述:

  價格:  字符類型設計爲  decimal(10,2); 10爲十進制,2保留兩位小數

表字段的添加 

  alter table staff add column  post  decimal(10,2)  not null  after  age  

  注:: staff:表名   

         post:添加的新字段  

         decimal(10,2)  添加的字段類型  

         after age:添加在那個字段後面 

表字段刪除

alter table staff drop column post 

   

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