当前位置:网站首页>SQL学习笔记(02)——数据库表操作
SQL学习笔记(02)——数据库表操作
2022-07-01 09:22:00 【雨轩GodLike】
目录内容
一、Mysql数据库操作
- 创建数据库
格式:create database 数据库的名字;
create database student;
- 删除数据库
格式:drop database 数据库的名字;
drop database student;
- 直看现有的数据库:
show databases;
二、Mysql中数据类型
1.整数和小数型
整数类型:int
小数类型:decimal 格式:decimal(总长度,小数位)
decimal(5,2) 要求传递过来的数据总长度是5位,小数位是2位
2.日期和时间类型
datetime YYYY-MM-DD HH:MM:SS
date YYYY-MM-DD
3.字符串类型
char(字符串的长度) 定长
varchar(字符串的长度) 变长
例如:
姓名 char(10) tom–>占3个字符 还剩7个字符的空间不会释放,系统会用空格给填充满
姓名 varchar(10) tom–>占3个字符 还剩7个字符被释放出来
三、创建和删除表操作
创建表语法格式
create table 表名(
列名1 数据类型,
列名2 数据类型,
列名3 数据类型
);
数据库中注释
单行注释:-- 注释的内容
多行注释:/* 注释的内容 */
切换数据库
格式:use 数据库的名字
打开表:查看表中有没有存入数据
设计表:查看表结构
删除表
删除单张表:drop table 表名;
删除多张表:drop table 表名1,表名2;
四、修改表结构
添加列
alter table 表名 add 列名数据类型;
删除列
alter table 表名 drop 列名;
修改列的数据类型
alter table 表名 modify 列名 新的数据类型;
修改列名
alter table 表名 change 旧列名 新列名 数据类型;
显示表结构
desc 表名;
检查性约束 check(限制列中的取值范围)
create table 表名(
列名1 数据类型 check(约束条件)
);
举例:表中id取值范围为5-20
create table students(
id int check(id>5 and id<20)
);
边栏推荐
- dsPIC30F6014a LCD 方块显示
- js valueOf 与 toString 区别
- pcl_ Viewer command
- es6-顶层对象与window的脱钩
- 集成积木报表报错 org.apache.catalina.core.StandardContext.filterStart 启动过滤器异常
- js 使用toString 区分Object、Array
- Understand shallow replication and deep replication through code examples
- Weidongshan board compilation kernel problem solving
- Shell script -if else statement
- Is it safe to dig up money and make new shares
猜你喜欢
Network counting 01 physical layer
How to solve the problem of fixed assets management and inventory?
3D printing Arduino four axis aircraft
3D打印Arduino 四轴飞行器
2.2 【pytorch】torchvision. transforms
2.3 【pytorch】数据预处理 torchvision.datasets.ImageFolder
[interview brush 101] linked list
nacos服务配置和持久化配置
Which method is good for the management of fixed assets of small and medium-sized enterprises?
Pain points and solutions of fixed assets management of group companies
随机推荐
Pain points and solutions of equipment management in large factories
【pytorch】nn. Crossentropyloss() and nn NLLLoss()
Shell script -select in loop
【pytorch】transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
Pain points and solutions of fixed assets management of group companies
Why is the Ltd independent station a Web3.0 website!
Mise en œuvre simple de l'équilibrage de la charge par nacos
Daily practice of C language - day 80: currency change
Mysql8.0 learning record 17 -create table
js原型陷阱
樹結構---二叉樹2非遞歸遍曆
Log4j 日志框架
How to realize the usage of connecting multiple databases in idel
短路运算符惰性求值
Is it safe to dig up money and make new shares
JS rewrite their own functions
I use flask to write the website "one"
【pytorch】nn.AdaptiveMaxPool2d
2.3 [pytorch] data preprocessing torchvision datasets. ImageFolder
Understand shallow replication and deep replication through code examples