当前位置:网站首页>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 .
边栏推荐
- Word——Word在试图打开文件时遇到错误的一种解决办法
- 3.10 haas506 2.0 development tutorial example TFT
- ANSI/UL 94 5-V级垂直燃烧试验
- 企业选型作业上常犯的一个错误
- Regular expressions (regular matching)
- sqlserver SQL Server Management Studio和Transact-SQL创建账户、创建访问指定数据库的只读用户
- MQ优缺点(2022.5.2-5.8)
- Video content production and consumption innovation
- Practical application of "experience" crawler in work
- CTF flow analysis common questions (II) -usb flow
猜你喜欢

嵌入式软件开发新趋势:DevOps

Business Intelligence BI and business management decision-making thinking 4: business cost analysis

连接实验室服务器

Cloud Native Landing Practice Using rainbond for extension dimension information

Lenovo Yoga 27 2022, full upgrade of super configuration

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

【UML】UML类图

ArcGIS无插件加载(无偏移)天地图

Regular expressions (regular matching)

Nodejs installation and introduction
随机推荐
阿里天池SQL训练营学习笔记5
4个技巧告诉你,如何使用SMS促进业务销售?
Opengauss database source code analysis series articles -- detailed explanation of dense equivalent query technology (Part 1)
Swin-transformer --relative positional Bias
小小笔记-整型提升(C语言)
Mipi protocol in RFFE
新版EasyGBS如何配置WebRTC视频流格式播放?
Cobbler is easy to use
Delete duplicate elements in the sorting linked list ii[unified operation of linked list nodes --dummyhead]
mysql中union和union all的区别
开发那些事儿:如何在视频中添加文字水印?
教你Selenium 测试用例编写
商业智能BI与业务管理决策思维之四:业务成本分析
How to use xUnit framework to maintain test cases?
设计电商秒杀系统
熵-条件熵-联合熵-互信息-交叉熵
Entry node of link in linked list - linked list topic
Development: how to install offline MySQL in Linux system?
VMware16安装Win11虚拟机(最全步骤+踩坑)
20220528【聊聊假芯片】贪便宜往往吃大亏,盘点下那些假的内存卡和固态硬盘