MySQL基本命令

MySQL数据库基本创建及相关代码( 初学,笔记)
1.创建数据库(学生管理系统)

use mysql;
create database xsgl;

2.查看数据库是否创建成功

show databases;

3.创建数据表

create table student
(s_name char(40) not null ,
s_num int(10) not null primary key,
s_ages int(10) not null ,
s_class char(40) not null);

4.查看数据表结构

desc student;

5.插入数据

insert information
values('张三',19030130,19,'数据科学与大数据技术'),
('李四',199030131,19,'数据科学与大数据技术');

6.查看数据(搜索数据)

select *
from information;

以上创建数据库,数据表并插入数据的步骤
同时还有其他的SQL语句
1.修改数据表的必要指令行

alter table +数据表名
	执行的命令行

2.在数据表中添加列(元素)

alter table information
add s_grade char(40) not null;

3.修改数据表中的元素类型

alter table information
modify s_grade int(10) not null;

MySQL的删除命令(在删除数据表时需在该表所在的数据库下执行)

drop database(table) 数据库名(数据表名);

常用命令

show databases;--查看数据库
show table;--查看数据表
desc 数据表名;--查看数据表结构
select *
from 数据表名();--搜索数据表内容(*搜索整个表,可以改为列名(元素名))
where 列名='数据';--条件语句,筛选出符合条件的内容
create table 表名2 like 表名1(已有表)--将表1的结构复制到表2

查找并插入

insert student1--studend1为空表
select s_name
from information--将formation 的s_name复制到student1中
where s_name='张三';--将符合条件的内容复制到student1中
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值