Sql语句的增删查改

  去官网下载Sql-dll-win64-3270200或者在我的链接里直接下载,把Sqlite3解压后配置Sqlite3d的环境变量,就可以开始使用了。

Sql安装及Sql语句的增删查改的基本使用
  链接:https://pan.baidu.com/s/17gxphz6QAUKdPMuzTxxMKA ,提取码:al8i
  可以先在CMD窗中练习一下
Sql安装及Sql语句的增删查改的基本使用
  1、首先创建一个表:
  create table User (userId integer,name text,score);
  2、增加数据:
  insert into User (userId,name,score) values (1001,‘孙悟空’,95);
  insert into User (userId,name,score) values (1002,‘猪悟能’,80);
  insert into User (userId,name,score) values (1003,‘沙悟净’,70);
  insert into User (userId,name,score) values (1004,‘唐玄奘’,20);
  3、删除单行数据:
  delete from User where name = ‘唐玄奘’;
  4、查找数据:
  查找单行数据:select * from User where userId = 1001;
  查找所有数据:select * from User;
  查找这个表有多少行:select count(*) from User;
  查找带判断条件的数据:select * from User where score > 80 and score < 100;
  5、更改数据:
  update User set score = 85 where userId = 1002;
  sql语句在unity中的使用:
  把Plugin文件夹拖到Unity的Assets文件下,然后新建一个脚本,脚本如下:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mono.Data.Sqlite;

public class Test : MonoBehaviour {

	// Use this for initialization
	void Start () {
        //Application.dataPath,当前工程的Assets路径
        Debug.Log(Application.dataPath);
        // SqliteConnection是我们当前工程和Sqlite数据库进行连接的一个类
        SqliteConnection connect = new SqliteConnection("Data Source = " + Application.dataPath + "/Data/data.db");//Data Source 是当前数据的一个来源,data.db是data.Base的缩写
        ////连接打开
        connect.Open();
        //创建表的Sql语句
        string tableCre = "create table if not exists User (userId integer,name text,score);";
        //命令
        SqliteCommand command = new SqliteCommand(tableCre, connect);
        //执行Sql语句非查询操作
        command.ExecuteNonQuery();
        //命令释放掉
        command.Dispose();
    }	
	// Update is called once per frame
	void Update () {
		
	}
}

在SqliteManager里面显示如下:
Sql安装及Sql语句的增删查改的基本使用

相关文章:

  • 2021-11-19
  • 2021-12-29
  • 2021-10-18
  • 2022-12-23
  • 2021-11-19
  • 2021-11-08
  • 2021-12-15
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-19
  • 2022-02-18
  • 2022-02-09
  • 2021-12-12
相关资源
相似解决方案