Sqlite如何创建双主键

创建双主键, 需要使用primary key 关键字:

string sql = “create table if not exists channel (” +
“ip TEXT not null, ” +
“port INTEGER not null, ” +
“channelId INTEGER not null,” +
“name TEXT, ” +
“type INTEGER, ” +
“unit TEXT,” +
“min TEXT, ” +
“max TEXT, ” +
“value TEXT, ” +
“lastReportTime TEXT, ” +
“status INTEGER not null, ” +
“primary key (ip, port, channelId) ” +
“)”;
try
{
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
}
catch (SQLiteException ex)
{
Console.WriteLine(ex);
}

以上列子创建了一个通道表, 使用IP, 端口和通道号三个字段为关键字.

Original: https://blog.csdn.net/weddell/article/details/122302165
Author: citip
Title: Sqlite如何创建双主键

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/815644/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球