3.mysql的表格创建和增删改查

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

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值