当前位置:网站首页>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();
}

}


原网站

版权声明
本文为[yaohuiyaoo]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140626299242.html