增加一列
alter table tableName add fieldName 字段类型
修改一列
alter table tableName modify (column) fieldName 字段类型
删除一列
alter table tableName drop column fieldName
建表语句
- 最简单的:
CREATE TABLE t1(
id int not null,
name char(20)
)ENGINE=InnoDB AUTO_INCREMENT=40 DEFAULT CHARSET=utf8 COMMENT='数据采集日志';
2.带主键的:
a:
CREATE TABLE t1(
id int not null primary key,
name char(20)
);
b:复合主键
CREATE TABLE t1(
id int not null,
name char(20),
primary key (id,name)
);
3.带默认值的:
CREATE TABLE t1(
id int not null default 0 primary key,
name char(20) default '1'
);
4.外键
create table orders(orderNumber integer not null,orderDate date,
requireDate date,shippedDate date,status1 varchar(20),
comments varchar(255),
cusNumber integer,
index cus(cusNumber),
primary key(orderNumber),
foreign key (cusNumber) references Customers(customerNumber)
)
5.自映射
create table employee (
eid int primary key,
ename varchar(20),
managerid int, -- 增加此字段记录员工的管理者ID
foreign key managerid references employee(eid)
);