gpt4 book ai didi

sql - 我应该将 Users 和 Staff 存储在同一张表中吗?

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:36:23 25 4
gpt4 key购买 nike

<分区>

我正在为我的新应用程序设计数据库,该应用程序的人员在系统中担任两个不同的角色。这两个组是用户和员工。主要区别是用户有activeUser,username,password,security-questionanswer 和 Staff 有 activeStaffposition。这两者还共享用户和员工所需的下一个字段,如 FirstNameLastNameMiddleEmail .最初我认为这将非常简单,我将添加标志 accountType 和选项 UserStaff。这是我的界面示例:

$('#frm_type').on('change',displayForm);
function displayForm() {
var fldType = $(this).find(':selected').data('type');

if(fldType === 'isUser') {
$('.isUser').show();
$('.isStaff').hide();
}

if(fldType === 'isStaff') {
$('.isStaff').show();
$('.isUser').hide();
}

if(!fldType) {
$('.isUser').hide();
$('.isStaff').hide();
}
}
#main-container {
padding-top: 20px;
}
.isUser {
display: none;
}
.isStaff {
display: none;
}
<!DOCTYPE html>
<html lang="en">

<head>
<title>My Application</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script language="javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script language="javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>

<body>
<div id="main-container" class="container">
<form name="frmSaveuser" id="frmSaveuser" class="frm-agencySubmit" data-frm="SaveUser" autocomplete="off">
<div class="form-group required">
<input type="text" class="form-control" name="frm_firstname" id="frm_firstname" placeholder="Enter First Name" maxlength="50" required>
</div>
<div class="form-group required">
<input type="text" class="form-control" name="frm_lastname" id="frm_lastname" placeholder="Enter Last Name" maxlength="50" required>
</div>
<div class="form-group">
<input type="text" class="form-control" name="frm_lastname" id="frm_lastname" placeholder="Enter Last Name" maxlength="1">
</div>
<div class="form-group required">
<input type="email" class="form-control" name="frm_email" id="frm_email" placeholder="Enter email" maxlength="80" required>
</div>
<div class="form-group required">
<select class="form-control" name="frm_type" id="frm_type" required>
<option value="">-- Select Account Type --</option>
<option value="1" data-type="isUser">User</option>
<option value="2" data-type="isStaff">Staff</option>
</select>
</div>
<div class="isUser">
<div class="form-group required">
<select class="form-control" name="frm_activeuser" id="frm_activeuser" required>
<option value="">-- Active User --</option>
<option value="0">No</option>
<option value="1">Yes</option>
</select>
</div>
<div class="form-group required">
<select class="form-control" name="frm_systemadmin" id="frm_systemadmin" required>
<option value="">-- System Admin --</option>
<option value="0">No</option>
<option value="1">Yes</option>
</select>
</div>
<div class="form-group required">
<input type="text" class="form-control" name="frm_username" id="frm_username" placeholder="Enter UserName" maxlength="50" required>
</div>
<div class="form-group password-container">
<input type="password" class="form-control" name="frm_password" id="frm_password" placeholder="Enter Password" maxlength="50" required>
</div>
<div class="form-group">
<select class="form-control" name="frm_questionid" id="frm_questionid">
<option value="">-- Select the question --</option>
<option value="1">What was the name of your first pet?</option>
<option value="2">In what city were you born?</option>
<option value="3">What is your mother's maiden name?</option>
<option value="4">What is your favorite vacation spot?</option>
<option value="5">What is your favorite musical group?</option>
<option value="6">Where did you meet your spouse?</option>
<option value="7">What model was your first car?</option>
</select>
</div>
<div class="form-group">
<input type="text" class="form-control" name="frm_answer" id="frm_answer" placeholder="Enter Answer" maxlength="100">
</div>
</div>
<div class="isStaff">
<div class="form-group required">
<select class="form-control" name="frm_activestaff" id="frm_activestaff" required>
<option value="">-- Active Staff --</option>
<option value="0">No</option>
<option value="1">Yes</option>
</select>
</div>
<div class="form-group required">
<input type="text" class="form-control" name="frm_position" id="frm_position" placeholder="Choose Position" required>
</div>
</div>
<button type="submit" name="frm_submit" id="frm_submit" class="btn btn-primary">Submit</button>
</form>
</div>
</body>

</html>

接下来是上述概念的问题:假设我们创建了帐户用户,但该帐户也必须是员工,或者以其他方式绕过员工也必须是用户。在这种情况下,我需要帐户类型的第三个选项,即 Both(用户和员工)。这将使查询数据变得更加困难,因为我们必须始终包含至少两个选项。我想知道是否有更好的方法来处理这个问题?我们还必须考虑在帐户之间切换,例如拥有用户帐户的人将成为员工或员工成为用户。这必须可用,我正在寻找有效和长期的解决方案。到目前为止,我的数据库中只有一个表存储用户和员工的信息。

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