现在的位置: 首页 > 数据库 > 正文

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

2018年09月03日 数据库 ⁄ 共 712字 ⁄ 字号 评论关闭

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 列名;

抱歉!评论已关闭.