当前位置:网站首页>MySQL Basics
MySQL Basics
2022-06-10 20:46:00 【Rulyc】
1、 Get your own computer on the LAN IP Address ipconfig
SQL Grammatical norms :
- 1、 One SQL Statement can span multiple lines , It ends with a semicolon
- 2、 If there is a syntax error in a statement , Then this statement and all subsequent statements will not be executed
- 3、SQL Commands are not case sensitive , Traditionally, database keywords are capitalized , Non key words in lowercase
- 4、SQL The command can use a single line comment (#…) And multiline comments (/…/), The contents of the comment will not be executed by the server
2、 Common command :
show databases; Displays all databases currently on the server
quit; Exit connection
use Database name ; Enter the specified database
show tables; Display all the data tables in the current database
desc The name of the table ; Describe which columns are in the table ( Header )
3、 frequently-used SQL command
a、 Discard the specified database , If it exists
DROP DATABASE IF EXISTS Database name ;
b、 create new database
CREATE DATABASE Database name ;
c、 Enter the created database
USE Database name ;
d、 Create a table to save data
CREATE TABLE Table name (
Field type ,
Field type
);
eg:
CREATE TABLE student(
sid INT,
name VARCHAR(8),
sex VARCHAR(1),
score INT
);
e、 insert data
INSERT INTO Table name VALUES();
eg:
INSERT INTO student VALUES('1','tom','M','87');
f、 Query data
SELECT * FROM Table name ;
g、 Update data
UPDATE Table name SET Field name 1 = ' Content ', Field name 2=' Content ' WHERE id = '1';
eg:
UPDATE user SET
upwd=’888888’,phone=’19912345678’
WHERE uid=’1’;
h、 Delete data
DELETE FROM Table name WHERE Conditions ;
eg:
DELETE FROM user WHERE uid='2';
4、 constraint
a、 Primary key constraint —— PRIMARY KEY
b、 Non empty constraint ——NOT NULL
c、 Unique constraint ——UNIQUE
d、 Default constraint ——DEFAULT
have access to DEFAULT Keyword declares the default value , There are two ways to use it
INSERT INTO laptop VALUES(1, DEFAULT,…);
INSERT INTO laptop(lid,price) VALUES(2,3000);
Insert values for specific columns , All other columns use default values
e、 Check constraint —— CHECK
Check constraints can be customized to validate the inserted data
CREATE TABLE student(
score TINYINT CHECK(score>=0 AND score<=100)
);
Mysql Checking constraints is not supported , It will reduce the speed of data insertion
f、 Foreign key constraints ——FOREIGN KEY
5、 Auto grow Columns AUTO_INCREMENTAUTO_INCREMENT: Automatic growth , If a column declares a self incrementing column , No manual assignment is required , The assignment is NULL, The current maximum value will be automatically obtained , Then add 1 Insert .
matters needing attention :
Only applicable to integer primary key columns
Allow manual assignment
eg: Primary key 、 Automatic growth 、 Foreign key instance
# Set client-side connection and server-side code
SET NAMES UTF8;
# Drop the database
DROP DATABASE IF EXISTS demo;
# Create database
CREATE DATABASE tedu CHARSET=UTF8;
# Enter the database
USE demo;
# Create a table to save Department data
CREATE TABLE dept(
did INT PRIMARY KEY AUTO_INCREMENT,
dname VARCHAR(8) UNIQUE
);
# insert data
INSERT INTO dept VALUES(10,' R & D department ');
INSERT INTO dept VALUES(20,' The Marketing Department ');
INSERT INTO dept VALUES(30,' Operation Department ');
INSERT INTO dept VALUES(40,' Testing department ');
# A table that holds employee data
CREATE TABLE emp(
eid INT PRIMARY KEY AUTO_INCREMENT,
ename VARCHAR(6),
sex BOOL, #1 male 0 Woman
birthday DATE,
salary DECIMAL(7,2),
deptId INT,
FOREIGN KEY(deptId) REFERENCES dept(did)
);
# insert data
INSERT INTO emp VALUES(NULL,'Tom',1,'1990-5-5',6000,20);
INSERT INTO emp VALUES(NULL,'Jerry',0,'1991-8-20',7000,10);
INSERT INTO emp VALUES(NULL,'David',1,'1995-10-20',3000,30);
INSERT INTO emp VALUES(NULL,'Maria',0,'1992-3-20',5000,10);
INSERT INTO emp VALUES(NULL,'Leo',1,'1993-12-3',8000,20);
INSERT INTO emp VALUES(NULL,'Black',1,'1991-1-3',4000,10);
INSERT INTO emp VALUES(NULL,'Peter',1,'1990-12-3',10000,10);
INSERT INTO emp VALUES(NULL,'Franc',1,'1994-12-3',6000,30);
INSERT INTO emp VALUES(NULL,'Tacy',1,'1991-12-3',9000,10);
INSERT INTO emp VALUES(NULL,'Lucy',0,'1995-12-3',10000,20);
INSERT INTO emp VALUES(NULL,'Jone',1,'1993-12-3',8000,30);
INSERT INTO emp VALUES(NULL,'Lily',0,'1992-12-3',12000,10);
INSERT INTO emp VALUES(NULL,'Lisa',0,'1989-12-3',8000,10);
INSERT INTO emp VALUES(NULL,'King',1,'1988-12-3',10000,10);
INSERT INTO emp VALUES(NULL,'Brown',1,'1993-12-3',22000,NULL);
边栏推荐
- 请问九洲期货是正规的吗?开户安不安全
- Explain L3 cache to solve circular dependency
- knife4j配置使用直接拷贝即可
- The national advanced computing industry innovation (Yichang) center was officially launched and jointly operated by Zhongke Shuguang and Shengzhe technologies
- 知识图谱/关系可视化
- synergy: server refused client with our name
- Microsoft Word 教程「5」,如何在 Word 中更改页边距、创建新闻稿栏?
- 2 pcs share a set of keyboard and mouse
- node(express)实现增删改查、分页等接口
- View play and earn will lead crypto games astray
猜你喜欢

canvas 高级功能(上)

揭秘:春晚微信红包,是如何抗住 100 亿次请求的?

LeetCode:1037. 有效的回旋镖————简单

The new audio infinix machine appears in the Google product library, and Tecno CaMon 19 is pre installed with Android 13

canvas 高级功能(中)

mysql基础篇之mysql在已有表中添加自动增加的主键(或任意一个字段)

vulnhub-The Planets: Earth

观点丨Play and Earn 会让加密游戏误入歧途
![[FAQ] summary of common problems and solutions during the use of rest API interface of sports health service](/img/9e/9ce804d84fb8ec9221b7c10bbd6c36.jpg)
[FAQ] summary of common problems and solutions during the use of rest API interface of sports health service

synergy: server refused client with our name
随机推荐
解决idea超过5个相同包的时候自动变成*的问题
pytorch深度学习——神经网络卷积层Conv2d
云原生社区 大佬博客
Cut rope / integer split
ResourceNotFoundException : Unable to find resource
【生成对抗网络学习 其一】经典GAN与其存在的问题和相关改进
JD released ted-q, a large-scale and distributed quantum machine learning platform based on tensor network acceleration
中衍期货公司是国内的正规平台吗?开户安全吗?想开个期货账户
Explain L3 cache to solve circular dependency
LeetCode:497. 非重叠矩形中的随机点————中等
Mysql database foundation
KCon 2022 议题大众评选火热进行中!不要错过“心仪”的议题哦~
安全隐患?意义有限?挡不住真煮迷你厨具火爆618
功耗开发经验分享:设计功耗大板
游戏兼容性测试(通用方案)
uni-app自定义导航
Microsoft Word 教程,如何在 Word 中更改页面方向、为页面添加边框?
割舍绳子/整数分割
Redis集群形式--哨兵模式集群和高可用模式集群---Redis学习笔记003
vulnhub-The Planets: Earth