MySQL 1

这篇博客介绍了如何使用MySQL进行数据库操作,包括创建数据库studentdb、定义表t_course、插入记录、更新字段值以及删除数据。涉及的SQL语句有CREATE DATABASE、USE、CREATE TABLE、INSERT INTO、REPLACE INTO、UPDATE和DELETE FROM。内容涵盖了数据库的基本操作,适合初学者学习。
摘要由CSDN通过智能技术生成
mysql> create database studentdb default character set utf8;
Query OK, 1 row affected
#建立数据库studentdb
mysql> use studentdb;
Database changed
#使用数据库
mysql> create table t_course (cno char(3) not null primary key,cname varchar(32) not null,cpoint smallint,remark varchar(500))engine=innodb;
Query OK, 0 rows affected
#建表t_course
mysql> insert into t_course set cno='C01',cname='android编程',cpoint=3,remark='手机编程';
Query OK, 1 row affected

mysql> insert into t_course set cno='C02',cname='java',cpoint=2,remark='编程语言';
Query OK, 1 row affected

mysql> replace into t_course set cno='C03',cname='python',cpoint=3,remark='编程语言';
Query OK, 1 row affected

mysql> insert into t_course(cno,cname,cpoint)values('C04','html','4');
Query OK, 1 row affected
#填表
mysql> update t_course set cname='java编程基础' where cno='C02';
Query OK, 1 row affected
Rows matched: 1  Changed: 1  Warnings: 0

mysql> update t_course set cpoint=cpoint+1 where cno='C03';
Query OK, 1 row affected
Rows matched: 1  Changed: 1  Warnings: 0

mysql> update t_course set cpoint=4 where cno='C01';
Query OK, 1 row affected
Rows matched: 1  Changed: 1  Warnings: 0
#更改表格中的数据

mysql> delete from t_course where cno='C03';
Query OK, 1 row affected

mysql> delete from t_course where cpoint<3;
Query OK, 1 row affected
#删除表中的数据

mysql> select * from t_course;
+-----+-------------+--------+----------+
| cno | cname       | cpoint | remark   |
+-----+-------------+--------+----------+
| C01 | android编程 |      4 | 手机编程 |
| C04 | html        |      4 | NULL     |
+-----+-------------+--------+----------+
2 rows in set

mysql> select cpoint from t_course;
+--------+
| cpoint |
+--------+
|      4 |
|      4 |
+--------+
2 rows in set

mysql> select cpoint from t_course where cno='C04';
+--------+
| cpoint |
+--------+
|      4 |
+--------+
1 row in set

mysql> select cpoint from t_course where cname='html';
+--------+
| cpoint |
+--------+
|      4 |
+--------+
1 row in set

mysql> select cno from t_course where cname='html';
+-----+
| cno |
+-----+
| C04 |
+-----+
1 row in set
#查询表格中的数据
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值