当前位置:网站首页>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();
}
}
边栏推荐
- [groovy] closure (closure parameter binding | curry function | rcurry function | ncurry function | code example)
- 3dsmax2018 common operations and some shortcut keys of editable polygons
- How to choose a panoramic camera that suits you?
- [goweb development] Introduction to authentication modes based on cookies, sessions and JWT tokens
- AutoCAD - continuous annotation
- Rip notes [rip message security authentication, increase of rip interface measurement]
- windows下Redis-cluster集群搭建
- Error statuslogger log4j2 could not find a logging implementation
- Flutter 小技巧之 ListView 和 PageView 的各种花式嵌套
- Decryption function calculates "task state and lifecycle management" of asynchronous task capability
猜你喜欢
质量体系建设之路的分分合合
AutoCAD - feature matching
数论函数及其求和 待更新
Special information | finance, accounting, audit - 22.1.23
MySQL in-depth learning - index creation and deletion, index design principles, index failure scenarios, query optimization, index push down ICP
"Measuring curve length" of CAD dream drawing
PostgreSQL 超越 MySQL,“世界上最好的编程语言”薪水偏低
Rip notes [rip message security authentication, increase of rip interface measurement]
669. 修剪二叉搜索树 ●●
3dsmax scanning function point connection drawing connection line
随机推荐
[groovy] closure (closure as function parameter | code example)
QT Bluetooth: a class for searching Bluetooth devices -- qbluetooth devicediscoveryagent
Stage experience
Data security -- 14 -- Analysis of privacy protection governance
2021 Higher Education Club Cup mathematical modeling national tournament ABCD problem - problem solving ideas
flutter 对象和列表
【acwing】528. cheese
On-off and on-off of quality system construction
xss注入
[Business Research Report] top ten trends of science and technology and it in 2022 - with download link
AutoCAD - continuous annotation
Research and forecast report on China's solution polymerized styrene butadiene rubber (SSBR) industry (2022 Edition)
[groovy] closure closure (customize closure parameters | customize a single closure parameter | customize multiple closure parameters | specify the default value of closure parameters)
Solutions and answers for the 2021 Shenzhen cup
[groovy] closure (closure parameter list rule | default parameter list | do not receive parameters | receive custom parameters)
49 pictures and 26 questions explain in detail what is WiFi?
The difference between bundle, chunk and module
2022-2028 global and Chinese virtual data storage Market Research Report
[groovy] closure (closure call is associated with call method | call () method is defined in interface | call () method is defined in class | code example)
AutoCAD - full screen display