數據庫在創建數據表的時候經常會報錯:
ERROR 1064 (42000): You have an error in your SQL syntax
出現這種情況的原因可能是:
1、拼寫錯誤
2、符合錯誤,例如()而不是{} 英文和中文符號;;的區別
3、使用了關鍵字
create table
ustomers(id int(11) not null primary key aotu_increment, name varchar(20) null, age int not null);
另外常用的修改表的sql語句小結1
修改表名
alter table
<舊錶名> rename [to] <行表名>;
修改字段的數據類型
alter table
<表名> modify <字段名> <數據類型>;
修改字段名
alter table
<表名> change <舊字段名><新字段名><新數據類型>;
添加字段
alter table
<表名> add <新字段名><新數據類型>[約束條件][first | after 已存在的字段名];
刪除字段
alter table
<表名>drop<字段名>;
修改字段的排列位置
alter table
<表名> modify <字段1> <數據類型> first |after <字段2>;
修改表的存儲引擎
alter table
<表名> engine=<更改後的存儲引擎名>;
刪除表的外健約束
alter table
<表名> drop foreign key <外健約束名>
“首先創建外健 constraint
外健約束名 foreign key (本表字段) references 外表名(字段)或者alter table table_name add constraint fk_column_id foreign key(column) references 主鍵表(column_id)”
刪除數據表
drop table [if
exists] 表1,表2....alter