当前位置:网站首页>Task01: getting to know database and SQL (Note 1)
Task01: getting to know database and SQL (Note 1)
2022-06-30 19:29:00 【Game programming】
This chapter mainly introduces the database , Consider ease of use and popularity , The course mainly uses MySql Conduct Introduce .
SQL Training camp page address :AI Training camp SQL- Alibaba cloud Tianchi
Tianchi Longzhu program training camp address :AI Training camp - Alibaba cloud Tianchi
1、 Database definition :
Save a lot of data , A collection of data processed by a computer that can be accessed efficiently
The computer system used to manage the database is called the database management system (DBNS)
2、DBMS species :
Classify according to data storage format : Hierarchical database (HDB)
relational database (RDB)—— Also known as RDBMS
Object-oriented database (OODB)
XML database (XMLDB)
Key value storage system (KVS),eg:MongoDB
Representative of RDBMS :
* Oracle Database: Oracle's RDBMS
* SQL Server: Microsoft's RDBMS
* DB2:IBM The company's RDBMS
* PostgreSQL: Open source RDBMS
* MySQL: Open source RDBMS
3、RDBMS Common system structure
client / Server type (C/S type )

I used the local MySQL The environment construction method is as follows :
Save space , I will give you a detailed introduction and write pdf In the , You can click the link to view :
http://tianchi-media.oss-cn-beijing.aliyuncs.com/dragonball/SQL/other/ Local MySQL Introduction to environment construction method .pdf
advantage : free , Enhance hands-on ability .
shortcoming : install 、 Configuration trouble , Data import 、 Exporting takes a long time .
4、SQL Concept : The language in which the database library is operated

The table structure stored in the database is similar to excel Rows and columns in , As shown in the figure above :
In the database , Lines are called records , Equivalent to a record
Columns are called fields , Represents the data items stored in the table
Where rows and columns meet is called a cell , Only one record can be entered in a cell
According to RDBMS Different categories of instructions given :
(1) Data definition language (DDL) Used to create or delete Database and surface . The instructions are :
- CREATE : Create objects such as databases and tables
DROP : Delete objects such as databases and tables
ALTER : Modify the structure of objects such as databases and tables (2) Data manipulation language (DML) Used to query or change The records in the table . The instructions are :
SELECT : Query data in table
INSERT : Insert new data into the table
UPDATE : Update the data in the table
DELETE : Delete data from table (3) Data control language (DCL) Used to confirm or cancel changes to data in a database . It can be done to RDBMS Whether or not the user has permission to operate the objects in the database ( Database table, etc ) To set . The instructions are :
COMMIT : Confirm changes to the data in the database
ROLLBACK : Cancel changes to the data in the database
GRANT : Give the user permission to operate
REVOKE : Cancel the user's operation permission 5、 Basic writing rules
(1) Use a semicolon (;) ending
(2) Case insensitive keywords , But the data inserted into the table is case sensitive
(3)Windows The system does not distinguish the case of table name and field name by default (linux/mac Is different )
(4) Constant is written in a fixed way eg:'abc', 1234, '26 Jan 2010', '10/01/26', '2010-01-26'…
(5) Words need to be separated by half width spaces or line breaks , And you can't use full width spaces as word separators , Otherwise, there will be mistakes , Unexpected results .
6、 Database creation (CREATE DATABASE sentence )
grammar :
create database< Database name >;
7、 The creation of a table (CREATE TABLE sentence )
grammar :
create table < Table name >
(< Name 1>< data type >< Constraints required >
< Name 2>< data type >< Constraints required >
< Name n>< data type >< Constraints required >
)
8、 Naming rules
(1) Only half width English letters can be used 、 Numbers 、 Underline (_) As a database 、 Table and column names
(2) The name must start with half letter
9、 Data type designation
The tables created by the database , All columns must have a data type specified , Each column cannot store data that does not match the data type of the column .
data type :
(1)INTEGER type Storage Integers The data type of the column of ( Digital ), Can't store decimals .
(2)CHAR type Store fixed length string , When the length of the string stored in the column does not reach the maximum length , Use half space to complement , Because it wastes storage space , So I don't use .
(3)VARCHAR type Storage ( variable ) Length string , Fixed length string will be supplemented with half width spaces when the number of characters does not reach the maximum length , But variable length strings are different , Even if the number of characters does not reach the maximum length , I don't use half space to make up .
(4)DATE type Storage date ( Specific date ) The data type of the column of ( Date type ).
10、 Setting of constraints
Constraints are in addition to data types , The data stored in the column is Limit perhaps Additional Conditional function .NOT NULLyes Non empty constraint , That is, data must be entered in the column .PRIMARY KEYyes Primary key constraint , Represents that the column is unique , You can get the data of a specific row through this column .
11、 Table deletion and update
(1) Delete table Syntax :
Drop table < Table name >
(2) Add columns ALTER TABLE sentence
ALTER TABLE < Table name > ADD COLUMN < Definition of columns >;
(3) Delete column ALTER TABLE sentence
ALTER TABLE < Table name > DROP COLUMN < Name >;
Be careful :ALTER TABLE Statement and DROP TABLE The sentence is the same , Cannot recover after execution . Mistakenly added columns can be through ALTER TABLE Statement delete , Or delete all the tables and create them again .
(4) Clear table contents
TRUNCATE TABLE TABLE_NAME;
advantage : comparisondrop``/``delete,truncateWhen used to clear data , The fastest .
(5) Update of data
UPDATE < Table name >
SET < Name > = < expression > [, < Name 2>=< expression 2>...];
WHERE < Conditions >; -- Optional , It's very important .
ORDER BY Clause ; -- Optional
LIMIT Clause ; -- Optional
Be careful : Use update Pay attention to adding where Conditions , Otherwise, all rows will be modified according to the statement
Use UPDATE You can also update the column to NULL( This update is commonly known as NULL Empty ). At this time, you only need to write the value on the right of the assignment expression directly as NULL that will do
UPDATE Statement and INSERT The sentence is the same , Can be NULL Use as a value .
however , Only unset NOT NULL Columns with constraints and primary key constraints can be cleared to NULL. If the column with the above constraints is updated to NULL, Will go wrong , With this INSERT Same statement .
(6) Multi column update
UPDATE Of the statement SET Clause supports multiple columns as update objects at the same time .( You can simplify the code by merging )(7) towards product Insert data into the table
INSERT INTO < Table name > ( Column 1, Column 2, Column 3, ……) VALUES ( value 1, value 2, value 3, ……);
Be careful :1、 Make a full column of the table INSERT when , You can omit the column list after the table name . VALUES The value of clause will be assigned to each column from left to right by default .
2、 Do it once INSERT Statement inserts a row of data
3、 When inserting multiple lines , It is usually necessary to cycle through the corresponding number of times INSERT sentence . In fact, a lot of RDBMS Both support inserting multiple rows of data at one time
4、INSERT The statement wants to assign... To a column NULL When the value of , Can be directly in VALUES Clause in the list of values NULL. Want to insert NULL Columns must not be set NOT NULL constraint .
5、 You can also insert default values into the table ( Initial value ). You can create a table by CREATE TABLE Set... In the statement DEFAULT Constraints to set default values .
6、 Use INSERT … SELECT Statement to copy data from other tables .
The answer to the exercise :
1、create database Addressbook;
create table Addressbook(
regist_no integer not null,
name varchar(128) not null,
address varchar(256) not null,
tel_no char(10),
mail_address char(20),
primary key(regist_no)
);
2、ALTER TABLE Addressbook ADD COLUMN postal_code char(8) not null;
3、DROP TABLE Addressbook;
4、# Deleted tables cannot be recovered , It can only be re inserted , Please be careful when deleting
author :wxiaoyiwenrong
Game programming , A game development favorite ~
If the picture is not displayed for a long time , Please use Chrome Kernel browser .
边栏推荐
- Ansi/ul 94 class 5-V vertical combustion test
- 配置服务器环境
- 法国A+ 法国VOC标签最高环保级别
- Develop those things: how to add text watermarks to videos?
- 基于STM32单片机的测温仪
- How to improve the three passive situations in data analysis
- How to use xUnit framework to maintain test cases?
- 20220607跌破建议零售价,GPU市场正全面走向供过于求...
- rust配置国内源
- Pyth-Solana链上联通现实的桥梁
猜你喜欢

How to seamlessly transition from traditional microservice framework to service grid ASM

简述机器学习中的特征工程

Nodejs 安装与介绍

连接实验室服务器

Kalman滤波器--从高斯融合推导

小球大小随机,随机运动碰撞

JVM常见问题

嵌入式软件开发新趋势:DevOps
![Delete duplicate elements in the sorting linked list ii[unified operation of linked list nodes --dummyhead]](/img/dd/7df8f11333125290b4b30183cfff64.png)
Delete duplicate elements in the sorting linked list ii[unified operation of linked list nodes --dummyhead]

Swin-transformer --relative positional Bias
随机推荐
rust配置国内源
Swin-transformer --relative positional Bias
拓维信息使用 Rainbond 的云原生落地实践
Swin-Transformer(2021-08)
开发那些事儿:如何在视频中添加文字水印?
设计电商秒杀系统
torch. roll
Trust configuring domestic sources
ROS advertisement data publishing tips - latch configuration
20200525-生物技术-四川师范大学自考生物技术(本科)考试计划.txt
20200525 Biotechnology - Sichuan Normal University self taught Biotechnology (undergraduate) examination plan txt
Pyth-Solana链上联通现实的桥梁
[community star selection] the 23rd issue of the July revision plan | bit by bit creation, converging into a tower! Huawei freebuses 4E and other cool gifts
Cobbler is easy to use
The cloud native landing practice of using rainbow for Tuowei information
The folder is transferred between servers. The folder content is empty
不同制造工艺对PCB上的焊盘的影响和要求
连接实验室服务器
PO模式简介「建议收藏」
ros advertise 发布数据小技巧--latch配置