gpt4 book ai didi

c++ - c++中的sqlite3创建语句和外键

转载 作者:行者123 更新时间:2023-11-28 07:09:32 26 4
gpt4 key购买 nike

我正在用 C++ 尝试 sqlite3 创建语句和外键,我提出了 4 个要求。

1) a employer can create a job position
2) a employer can view the form reject or shortlist the applicant for interview
3) a applicant may apply for a job position
4) a applicant must fill up their details and submit the form if they are keen to apply for a position

这是我写的

雇主表

/*SQL statement for employer table*/
char *sql;
sql = "CREATE TABLE EMPLOYER(" \
"ID INT PRIMARY KEY NOT NULL," \
"NAME TEXT NOT NULL," \
"ROLE TEXT NOT NULL );";

职位表

/*SQL statement for jobposition table */
char *sql;
sql = "CREATE TABLE JOBPOSITION(" \
"ID INT PRIMARY KEY NOT NULL," \
"JOBPOSITION TEXT NOT NULL," \
"OUTCOME TEXT NOT NULL );";

表单表格

/*SQL statement for form table*/
char *sql;
sql = "CREATE TABLE FORM (" \
"ID INT PRIMARY KEY NOT NULL," \
"FOREIGN KEY (ID) REFERENCES APPLICANT(ID)",
"FOREIGN KEY (ID) REFERENCES JOBPOSITION(ID)",
FOREIGN KEY (ID) REFERENCES EMPLOYER(ID)" );";

申请人表

 /*SQL statement for applicant table*/
char *sql;
sql = "CREATE TABLE APPLICANT (" \
"ID INT PRIMARY KEY NOT NULL," \
"APPLICANT_NAME TEXT NOT NULL," \
"APPLICANT_ADDRESS TEXT NOT NULL," );";

我不确定这是否正确,因为我刚开始学习数据库并需要一些帮助。

最佳答案

我不知道你所说的“正确”是什么意思,所以我将向你展示我将如何做到这一点:

CREATE TABLE users (
id INT NOT NULL PRIMARY_KEY AUTO_INCREMENT,
name TEXT NOT NULL,
address TEXT NOT NULL,
role TEXT NOT NULL, /* employer, applicant etc. */
);

CREATE TABLE job_positions (
id INT NOT NULL PRIMARY_KEY AUTO_INCREMENT,
creator_id INT NOT NULL FOREIGN_KEY REFERENCES users(id),
description TEXT NOT NULL,
outcome TEXT NOT NULL,
);

CREATE TABLE forms (
id INT NOT NULL PRIMARY_KEY AUTO_INCREMENT,
position_id INT NOT NULL FOREIGN_KEY REFERENCES job_positions(id)
creator_id INT NOT NULL FOREIGN_KEY REFERENCES users(id)
);

这样用户与job_positions和forms就有了1-N的关系;和 job_positions 与表单具有 1-N 关系。也就是说,job_positions属于用户;和表单属于用户和职位。

关于c++ - c++中的sqlite3创建语句和外键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21226267/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com