3.mysql的表格创建和增删改查
标签(空格分隔): 2mysql
一、表格创建
1.mysql> create database ishop1; 建一个数据库ishop1
2.mysql> use ishop1; 使用数据库ishop1
3 创建commoditytype表格
3-1 commoditytype表格
3-1-1.mysql> Create table commoditytype(
-> ct_id int(11) primary key,
-> ct_num varchar(50) not null
-> )default charset=utf8; 创建commoditytype的表格
Query OK, 0 rows affected (0.39 sec)
- 每个字段编辑完以逗号结尾
- 注意字段最后一行没有逗号
- 最后一行半个括号,设置默认字符集为utf-8
3-1-2.mysql> show tables; 显示表格(可查看ishop数据源下的所有表格)
±-----------------+
| Tables_in_ishop1 |
±-----------------+
| commoditytype |
±-----------------+
1 row in set (0.00 sec)
3-1-3.mysql> desc commoditytype; 显示表内容
±-------±------------±-----±----±--------±------+
| Field | Type | Null | Key | Default | Extra |
±-------±------------±-----±----±--------±------+
| ct_id | int(11) | NO | PRI | NULL | |
| ct_num | varchar(50) | NO | | NULL | |
±-------±------------±-----±----±--------±------+
2 rows in set (0.09 sec)
3-2 创建commodity表格;
3-2-1 mysql> create table commodity(
-> c_id int(11) primary key,
-> c_name varchar(50) not null,
-> c_madein varchar(50) not null,
-> c_type int(11) not null,
-> c_inprice int(11) not null,
-> c_outprice int(11) default null,
-> c_num int(11) default ‘100’,
-> constraint fk_1 foreign key (c_type) references commoditytype (ct_id)
-> )default charset=utf8;
Query OK, 0 rows affected (0.33 se