mysql 基本语法学习1(数据库、数据表、数据列的操作)

本文介绍了MySQL的基本操作,包括数据库的创建、删除、显示等;数据表的创建、修改、删除等;以及数据列的添加、删除和修改等内容。适合初学者快速掌握MySQL的基本用法。

今天学习了一下mysql语法,并记录下来

1、mysql的数据库操作

/***1、操作数据库的语法 ***/

-- 1)显示所有数据库 --
show databases;

-- 2)创建数据库 --
create database testdb;

-- 3)删除数据库 --
drop database testdb;

-- 4)使用数据库 --
use testdb;

-- 5) 查询数据库下所有表 --
show tables;

2、mysql的数据表操作

/*** 2、操作数据表的语法 ***/

-- 1)创建新的数据表 --
create table Student(
    Uid int auto_increment primary key,  -- 自增Uid,主键
    StuName varchar(20) not null,
    StuAge int not null,
    StuSex varchar(10) not null,
    StuMeg varchar(100) null
);

-- 2)使用旧表创建新表 --
create table Student1 like Student;

-- 3)添加数据到数据表 --
insert into Student(StuName,StuAge,StuSex,StuMeg) values('张三',12,'','性格开朗');
insert into Student(StuName,StuAge,StuSex,StuMeg) values('丽丝',14,'','性格活泼');
insert into Student(StuName,StuAge,StuSex,StuMeg) values('王琦',15,'','沉默寡言');

-- 4)修改数据表数据 --
update Student set StuName='张泉' where Uid='1';

-- 5)查询数据表数据 --
select * from  Student;

-- 6) 删除数据表 -- 
drop table Student;

-- 7)清空数据表数据(新增数据时,Uid从0开始) ---
truncate table Student;

-- 8) 清空指定数据表数据(新增时,Uid不会从0开始)--
delete from Student where Uid='3';

3、mysql的数据列操作

/***数据表的行、列操作 ***/

-- 1) 为数据表添加列名 ---
alter table Student add column StuClass varchar(20);

-- 2) 为数据表删除列名 --
alter table Student drop column StuClass;

-- 3) 修改列名的数据类型 --
alter table Student modify column StuClass int;

-- 4) 同时修改列名的数据类型和名称 --
alter table Student change StuClass sClass varchar(30);

 Ps:

学习网址:http://www.jb51.net/article/28288.htm

转载于:https://www.cnblogs.com/xielong/p/7240616.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值