MySql 创建和操纵表

创建表

create table customers
(
  cust_id     int       not null   auto_increment,
  cust_name    char(50)   not null,
  cust_address  char(50)   null,
  cust_city    char(50)   null,
  cust_state   char(5)    null,
  cust_zip     char(10)   null,
  cust_country  char(50)   null,
  cust_contact  char(50)   null,
  cust_email   char(255)   null,
  primary key (cust_id)
) engine=innodb;

更新表

//增加字段
alter table vendors
add vend_phone char(20);

//删除字段
alter table vendors
drop column vend_phone;

//添加外键约束
alter table orderitems
add constrain fk_orderitems_orders
foreign key (order_num) references orders (order_num);

//删除外键约束
//可以通过show create table orderitems查看外键
drop foreign key fk_orderitems_orders;

//删除表
drop table customers;

//重命名表
rename table customers to customers_new;



参考书籍:

  • MySQL必知必会

你可能感兴趣的:(MySql 创建和操纵表)