创建双主键, 需要使用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, 端口和通道号三个字段为关键字.