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中