当前位置:网站首页>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)
);
边栏推荐
- 【电赛训练】红外光通信装置 2013年电赛真题
- Why is the Ltd independent station a Web3.0 website!
- [ESP nanny level tutorial] crazy completion chapter - Case: ws2812 light control system based on Alibaba cloud, applet and Arduino
- 2022.02.15_ Daily question leetcode six hundred and ninety
- OSPF - virtual link details (including configuration commands)
- 樹結構---二叉樹2非遞歸遍曆
- Weidongshan board compilation kernel problem solving
- es6-顶层对象与window的脱钩
- Click the screen with your finger to simulate F11 and enter the full screen
- MT7628K eCos开发入门
猜你喜欢
Ranking list of domestic databases in February, 2022: oceanbase regained the "three consecutive increases", and gaussdb is expected to achieve the largest increase this month
How to solve the problem of fixed assets management and inventory?
【pytorch】nn. Crossentropyloss() and nn NLLLoss()
【pytorch】2.4 卷积函数 nn.conv2d
小鸟识别APP
Phishing identification app
2.3 [pytorch] data preprocessing torchvision datasets. ImageFolder
MapReduce编程基础
Tree structure -- binary tree 2 non recursive traversal
Simple load balancing with Nacos
随机推荐
nacos简易实现负载均衡
js valueOf 与 toString 区别
Databinding source code analysis
Daily practice of C language - day 80: currency change
Ranking list of domestic databases in February, 2022: oceanbase regained the "three consecutive increases", and gaussdb is expected to achieve the largest increase this month
js原型陷阱
钓鱼识别app
Pain points and solutions of fixed assets management of group companies
【pytorch】transforms. Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
OSPF - virtual link details (including configuration commands)
JS rewrite their own functions
JS scope chain and closure
I use flask to write the website "one"
[pytorch] 2.4 convolution function nn conv2d
JS prototype inheritance can only inherit instances, not constructors
Implementation and application of queue
js变量提升(hoisting)
Design and manufacture of simple digital display electronic scale
Learning practice: comprehensive application of cycle and branch structure (II)
[ESP nanny level tutorial] crazy completion chapter - Case: chemical environment system detection based on Alibaba cloud and Arduino, supporting nail robot alarm