当前位置:网站首页>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);
边栏推荐
- Key points of lldp protocol preparation
- 【Educational Codeforces Round 120 (Rated for Div. 2)】C. Set or Decrease
- Cloud native community boss blog
- Mixin -- mixed
- 中衍期货靠谱吗?是不是正规期货公司?开户安全吗?
- Esp8266 system environment setup
- Canvas advanced functions (medium)
- 一个10年左右的老程序员说:简单CRUD功能进入无码开发时代1 之 增删改查接口信息
- canvas 高级功能(中)
- knife4j配置使用直接拷贝即可
猜你喜欢

服务管理与通信,基础原理分析

获取列表中最大最小值的前n个数值的位置索引的四种方法

Stacked bar graph move the mouse into the tooltip to prompt that the filter is 0 element, so as to realize custom bubbles

Elastic-Job的快速入门,三分钟带你体验分布式定时任务

暗黑破坏神不朽WIKI地址 暗黑破坏神不朽数据库地址分享

电子招标采购商城系统:优化传统采购业务,提速企业数字化升级

hidden danger? Limited meaning? Can't stop the real cooking Mini kitchenware hot 618

pytorch深度学习——卷积操作以及代码示例

传音 Infinix 新机现身谷歌产品库,TECNO CAMON 19 预装 Android 13

Diablo immortal wiki address Diablo immortal database address sharing
随机推荐
【录入课本latex记录】
Fs4060a is a 4.2v/3a charging IC
synergy: server refused client with our name
堆叠条形图鼠标移入tooltip中提示过滤为0元素,实现自定义气泡
pdf.js-----js解析pdf文件实现预览,并获取pdf文件中的内容(数组形式)
Recommend a crud tool that may become the best crud tool in 2019 during the National Day
vulnhub-The Planets: Earth
synergy: server refused client with our name
C language floating point number storage form
魔塔类游戏实现源码及关卡生成
功耗开发经验分享:设计功耗大板
AttributeError: module ‘collections‘ has no attribute ‘MutableMapping‘
中国工科研究生200多篇英文论文中最常见的习惯(The Most Common Habits from more than 200 English Papers written by Gradua)
The most common habits from more than 200 English papers written by gradua
Does Seata still not support sqlserver?
Cloud native community boss blog
Is Jiuzhou futures regular? Is it safe to open an account
Explain L3 cache to solve circular dependency
揭秘:春晚微信红包,是如何抗住 100 亿次请求的?
Enhance the target method with surround notifications - extract notes