当前位置:网站首页>Unity and database
Unity and database
2022-07-05 04:52:00 【yaohuiyaoo】
mount this database ——》 Connect your own computer host ——》 Create database
One . Database design
1. In database design , How to represent the relationship between databases ?
relational model
2. Entity set X and Y What kinds of relationships exist ?
One to many , one-on-one , For one more , Many to many
3, What are the functions of the three paradigms of database ?
The goal of the first paradigm is to ensure the atomicity of each column
The second formula requires each table to describe one thing
If the first relationship satisfies 2NF, Besides, columns other than primary keys do not pass dependent primary keys
4, Database design in the project development cycle
Demand analysis stage : Analyze customers' business and data processing requirements
Outline design stage : Design database E-R Model diagram , Confirm that the requirement information is correct and complete
Detailed design stage : Apply three paradigms to audit database structure
Code writing phase : Physically implement the database , Writing and implementing applications
Software testing phase :
Installation and deployment :
5 draw E-R chart
The symbol rectangle is an entity
The symbol ellipse is an attribute
Square is relation
Two . Add, delete, change and check the database
1. Login database command :mysql -h( Server host address ( This machine can omit ))-u( user name ) -p( password ); Note that the content in brackets is the content required in the brackets immediately after
2. Create database :create database Database name ;
3. View all databases :show databases;
4. Access to database :use Database name ; // The entered database can only be existing
5. Delete database :drop database Database name ;
Be careful :. After entering the data, you can modify and add the data in the table
6. Create table :create table Table name ( Field 1 data type [ Field properties ][ constraint ][ Indexes ],…);
Field constraints
Non empty constraint not null Field cannot be empty
Default constraint default Assign the default value of a field
Unique constraint unique key Set the unique value of the field , Allow null , But only one can be empty
Primary key constraint primary key Set the field as the primary key of the table , It can uniquely identify the record of this table
Foreign key constraints foreign key Used to establish a relationship between two tables , You need to specify which field of the main table to refer to
Automatic growth auto_increment Set the column as a self incrementing field , By default, each self increment 1, Usually used to set the primary key
7. See if the table exists :use Table name
8. View all tables :show tables;
9. Check the parameters in the table :desc Table name ;
10 Delete table :drop table Table name ;
11. insert data :insert into Table name ( Field 1, Field 2, Field 3)value( data 1, data 2, data 3)
12. Modifying data :update Table name set Field 1= Revised data where Field = data
Be careful : Satisfy where The data matching will be modified later
13. Delete data :delete from Table name where Field = data
Be careful : Satisfy where The following conditions will be deleted
3、 ... and unity Use database under
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MySql.Data.MySqlClient;
public class Test2 : MonoBehaviour {
void Start () {
Startdata();
}
void Startdata()
{
string a = "server=localhost;database=student;userid=root;password=root";
//serveer= Host name database= Database name userid= user name password= password
// Create objects that connect to the database
MySqlConnection con = new MySqlConnection(a);// Connect data
// Open the connection
con.Open();
// Specific statements for table operations
string sql = "insert into xinxi(name,sex,age) value(' drug ',' male ',18)";//"insert into Table name ( Field 1, Field 2, Field 3) value( data 1, data 2, data 3);
// Create operands
MySqlCommand com = new MySqlCommand(sql, con);// Execute the operation statement on the table
if (com.ExecuteNonQuery() > 0)
{
print(" success ");
}
// Query the contents of the table
string selec = "select *from xinxi";// Query statement
MySqlCommand cad = new MySqlCommand(selec, con);
MySqlDataReader reader = cad.ExecuteReader();
while (reader.Read())
{
int id = reader.GetInt32("id");
string name = reader.GetString("name");
string sex = reader.GetString("sex");
print(id + "\t" + name + "\t" + sex);
}
reader.Close();
con.Close();
}
}
边栏推荐
- windows下Redis-cluster集群搭建
- A survey of automatic speech recognition (ASR) research
- Looking at Chinese science and technology from the Winter Olympics: what is the mystery of the high-speed camera that the whole people thank?
- [Business Research Report] top ten trends of science and technology and it in 2022 - with download link
- AutoCAD - scaling
- 54. 螺旋矩阵 & 59. 螺旋矩阵 II ●●
- 2020-10-27
- Inline built-in function
- 2021 higher education social cup mathematical modeling national tournament ABCD questions - problem solving ideas - Mathematical Modeling
- AutoCAD - set layer
猜你喜欢
The 22nd Spring Festival Gala, an immersive stage for the yuan universe to shine into reality
次小生成树
PostgreSQL 超越 MySQL,“世界上最好的编程语言”薪水偏低
数论函数及其求和 待更新
【Leetcode】1352. Product of the last K numbers
AutoCAD - feature matching
3dsmax scanning function point connection drawing connection line
[groovy] closure (closure parameter list rule | default parameter list | do not receive parameters | receive custom parameters)
Create a pyGame window with a blue background
2022 thinking of mathematical modeling D problem of American college students / analysis of 2022 American competition D problem
随机推荐
2020-10-27
SQL set operation
AutoCAD - feature matching
SQLServer 存储过程传递数组参数
AutoCAD - stretching
Decryption function calculates "task state and lifecycle management" of asynchronous task capability
3dsmax common commands
Construction d'un Cluster redis sous Windows
Create a pyGame window with a blue background
Research and forecast report on China's solution polymerized styrene butadiene rubber (SSBR) industry (2022 Edition)
Number theoretic function and its summation to be updated
LeetCode之单词搜索(回溯法求解)
中国AS树脂市场调研与投资预测报告(2022版)
AutoCAD - full screen display
[AI bulletin 20220211] the hard core up owner has built a lidar and detailed AI accelerator
質量體系建設之路的分分合合
计组笔记(1)——校验码、原补码乘除计算、浮点数计算
Private collection project practice sharing [Yugong series] February 2022 U3D full stack class 006 unity toolbar
49 pictures and 26 questions explain in detail what is WiFi?
History of web page requests