表employeeAccount
:
CREATE TABLE employeeAccount
(
employAccID NUMBER(2),
emplyUsername VARCHAR(20),
emplyFirstName VARCHAR(20),
emplyLastName VARCHAR(20),
)
INSERT INTO employeeAccount(employAccID ,emplyUsername ) VALUES (1,'TestAccount1')
INSERT INTO employeeAccount(employAccID ,emplyUsername ) VALUES (2,'TestAccount2')
表JobRole
:
CREATE TABLE Jobrole
(
jobNo NUMBER(2),
jobName VARCHAR(20),
)
INSERT INTO Jobrole(jobNo ,jobName) VALUES (001,'Admin')
INSERT INTO Jobrole(jobNo ,jobName) VALUES (002,'CEO')
这是我的employeeJob
代码:
CREATE TABLE employeeJob
(
empid NUMBER(2),
empjob NUMBER(2),
CONSTRAINT pk_employeeJob PRIMARY KEY(empid,empjob),
CONSTRAINT fk_empassignjob1 FOREIGN KEY(empid) REFERENCES employeeAccount(employAccID),
CONSTRAINT fk_empassignjob2 FOREIGN KEY(empjob) REFERENCES Jobrole(jobNo)
)
以下是插入查询:
INSERT INTO employeeJob(empid,empjob)
VALUES (1,'001')
任何想法如何让它自动从emplyFirstName
表格和emplyLastName
中获取employeeAccount
,employeeJob
等所有数据。插入employeeAccount
。我该怎么做才能让它自动插入从employeeJob
复制到.round {
position: relative;
}
.round label {
background-color: #fff;
border: 1px solid #ccc;
border-radius: 50%;
cursor: pointer;
height: 28px;
left: 0;
position: absolute;
top: 0;
width: 28px;
}
.round label:after {
border: 2px solid #fff;
border-top: none;
border-right: none;
content: "";
height: 6px;
left: 7px;
opacity: 0;
position: absolute;
top: 8px;
transform: rotate(-45deg);
width: 12px;
}
.round input[type="checkbox"] {
visibility: hidden;
}
.round input[type="checkbox"]:checked+label {
background-color: #66bb6a;
border-color: #66bb6a;
}
.round input[type="checkbox"]:checked+label:after {
opacity: 1;
}
html,
body {
height: 100%;
margin: 0;
}
body {
background-color: #f1f2f3;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
}
.container {
margin: 0 auto;
}
表的其他数据?
答案 0 :(得分:1)
是的,你可以,
INSERT INTO table2
SELECT * FROM table1
WHERE condition;
您可以自table2
自动填充table1
。如果您想要所有记录,请忽略WHERE
条件。但是,如果您只想自动填充从table1
到table2
的某些记录,请在condition
语句中填写WHERE
。
答案 1 :(得分:0)
您可以在插入内的employeejob
表格上创建触发器,如
Create trigger trgGetOtherDetails
On employeejob AFTER INSERT -- the AFTER key word is Necessary
AS
BEGIN
Declare @emplyFirstname varchar(30),
@emplyLastname varchar(30),
@empId varchar(5)
select @empId = empId from inserted
Select @emplyFirstname = emplyFirstname, @emplyLastname = emplyLastname from employeeAccount where employAccID = @empId
Update employeejob
Set emplyFirstname = @emplyFirstname,
emplyLastname = @emplyLastname
Where empId = @empId
END