当前位置:网站首页>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();
}
}
边栏推荐
- Interface joint commissioning test script optimization V5.0 (end)
- Redis 排查大 key 的4种方法,优化必备
- Forecast report on research and investment prospects of Chinese wormwood industry (2022 Edition)
- Download the details and sequence of the original data access from the ENA database in EBI
- 669. Prune binary search tree ●●
- AutoCAD - graphic input and output
- PostgreSQL surpasses mysql, and the salary of "the best programming language in the world" is low
- [groovy] closure (closure call is associated with call method | call () method is defined in interface | call () method is defined in class | code example)
- MySQL in-depth learning - index creation and deletion, index design principles, index failure scenarios, query optimization, index push down ICP
- 次小生成树
猜你喜欢
Solution of circular dependency
Introduction to JVM principle and process
Number theoretic function and its summation to be updated
AutoCAD - lengthening
数论函数及其求和 待更新
Setting up redis cluster cluster under Windows
The 22nd Spring Festival Gala, an immersive stage for the yuan universe to shine into reality
Special information | real estate and office buildings - 22.1.9
AutoCAD - continuous annotation
2022-2028 global and Chinese equipment as a Service Market Research Report
随机推荐
xss注入
[ideas] 2021 may day mathematical modeling competition / May Day mathematical modeling ideas + references + codes
Wenet: E2E speech recognition tool for industrial implementation
Solutions and answers for the 2021 Shenzhen cup
2022 thinking of mathematical modeling a problem of American college students / analysis of 2022 American competition a problem
Looking at Chinese science and technology from the Winter Olympics: what is the mystery of the high-speed camera that the whole people thank?
[groovy] closure (closure as function parameter | code example)
Special information | real estate and office buildings - 22.1.9
2021 electrician cup idea + code - photovoltaic building integration plate index development trend analysis and prediction: prediction planning issues
中国AS树脂市场调研与投资预测报告(2022版)
2021 electrician cup (the 12th "China Society of electrical engineering Cup" National Undergraduate electrician mathematical modeling) detailed ideas + codes + references
Flink cluster configuration
AutoCAD - graphic input and output
Research and forecast report on China's solution polymerized styrene butadiene rubber (SSBR) industry (2022 Edition)
2021 higher education social cup mathematical modeling national tournament ABCD questions - problem solving ideas - Mathematical Modeling
CUDA Programming atomic operation atomicadd reports error err:msb3721, return code 1
3dsmax2018 common operations and some shortcut keys of editable polygons
中国溶聚丁苯橡胶(SSBR)行业研究与预测报告(2022版)
Redis 排查大 key 的4种方法,优化必备
English topic assignment (26)