SQL语句

创建数据库的表:create table 表名:

->create table test(
-> test_id int,
-> test_price decimal,
-> test_name varchar(255) default 'hsh',
-> test_desc text,
-> test_img blob,
-> test_date datetime);

修改表结构:

修改表结构使用alert table,修改表结构包括增加列定义,修改列定义,删除列,重命名列等操作。

增加列定义:

->alter table test add(
-> aaa varchar(20) default 'xxx',
-> bbb varchar(30)
-> );

注意:在MYSQL中字符串用单引号。

修改列定义:

-> alter table test
-> modify aaa varchar(30);

 从数据库中删除列:

-> alter table test drop aaa;

重命名数据表:

 -> alter table test rename to newtest;

重命名字段名:

-> alter table newtest change aaa eee int;

删除表:

drop table 表名;

drop table newtest;

效果

truncate:截断表

作用:删除该表里面的全部数据但保留表结构。

truncate 表名;

只有O和1的世界是简单的!
原文地址:https://www.cnblogs.com/hinux/p/9670991.html