当前位置:网站首页>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 .
边栏推荐
- MQ优缺点(2022.5.2-5.8)
- 微信小程序快速入门 --项目介绍
- Gateway服务网关
- RFFE中MIPI协议
- France a+ France VOC label highest environmental protection level
- NBI visual platform quick start tutorial (V) introduction to editor functions and operations
- Iris, the web framework of go
- Evolution of screen display technology
- 4个技巧告诉你,如何使用SMS促进业务销售?
- 熵-条件熵-联合熵-互信息-交叉熵
猜你喜欢

Lenovo Yoga 27 2022, full upgrade of super configuration

【UML】UML类图

不同制造工艺对PCB上的焊盘的影响和要求

dtd建模

Evolution of screen display technology

浏览器窗口切换激活事件 visibilitychange

Nodejs installation and introduction

France a+ France VOC label highest environmental protection level

Personally test the size of flutter after packaging APK, quite satisfied

3.10 haas506 2.0 development tutorial example TFT
随机推荐
go之web框架 iris
Task04:集合运算-表的加减法和join等--天池龙珠计划SQL训练营学习笔记
全技术栈、全场景、全角色云原生系列培训重磅首发,助力企业打造硬核云原生技术团队
Electron 入门
教你Selenium 测试用例编写
浏览器窗口切换激活事件 visibilitychange
dtd建模
Sqlserver SQL Server Management Studio and transact SQL create accounts and create read-only users to access the specified database
一套十万级TPS的IM综合消息系统的架构实践与思考
德国AgBB VoC有害物质测试
Kalman filter -- Derivation from Gaussian fusion
slice
France a+ France VOC label highest environmental protection level
How JS correctly clears all child elements under an element
rust配置国内源
Go语言学习教程(十)
Ditto设置全局仅粘贴文本快捷键
The folder is transferred between servers. The folder content is empty
20220528【聊聊假芯片】贪便宜往往吃大亏,盘点下那些假的内存卡和固态硬盘
NBI可视化平台快速入门教程(五)编辑器功能操作介绍