【mysql】表的創建以及基本操作

1.表的創建

  create table tablennme(object type);

   如川建一個book的表

  create table book(book_id int(5),

                                   book_name char(20),

                                   book_author char(20));

  表示有一個book_id ,book_name ,book_author的列,類型分別爲int char char;

2.表的插入列

  alter table tablename add newlinename type;

    如在上例中增加列book_date,類型爲date;

     alter table book addbook_date date;

3.修改表中數據

   update tablename set  需修改的地方 where 限定修改的地點

    如已有book_id=1,book_name=mysql,book_author=abc,book_date=2013-12-6;現修改book_author=bcd;

  update book set book_author=bcd where book_id=1;

4.修改列的類型

  alter table tablename modify 列名 新類型

  如將book_id的int 變爲char;

  alter table book modfiy book_id char(5);

5修改列名

  alter table tablename change 原名 新名 新類型

 6.修改列的順序

 alter table tablename modify 列名 類型 after 另一列

7.刪除列

 alter table tablename drop 列名;

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