0
I intend to do Insert in the salary column and table function_name function which is foreign key in department table and this table is foreign key in official table...
But the two columns salary and payroll has to be done from the working table through the Id_deprtamento to get the Id_funcao that is inside the table
I did so
CREATE TABLE FUNCIONARIO
(
ID_FUNCIONARIO INT IDENTITY(1,1),
NOME_FUNCIONARIO VARCHAR(100) NOT NULL,
NOME_PAI VARCHAR(100) NOT NULL,
NOME_MAE VARCHAR(100)NOT NULL,
N_BI VARCHAR(50)UNIQUE NOT NULL,
DATA_NASC VARCHAR(100) NOT NULL,
GENERO VARCHAR(100) NOT NULL,
ESTA_CIVIL VARCHAR(100)NOT NULL,
FOTO VARCHAR (100) NOT NULL,
ID_DEPARTAMENTO INT,
ID_MUNICIPIO INT,
DATA_HORA VARCHAR (100)NOT NULL,
USUARIO VARCHAR (100)NOT NULL,
CONSTRAINT PK_FUNC PRIMARY KEY (ID_FUNCIONARIO),
CONSTRAINT PK_FUNC_MUNI FOREIGN KEY (ID_MUNICIPIO)
REFERENCES FUNCAO (ID_FUNCAO),
CONSTRAINT PK_FUNC_DEP FOREIGN KEY (ID_DEPARTAMENTO)
REFERENCES DEPARTAMENTO (ID_DEPARTAMENTO)
)
CREATE TABLE DEPARTAMENTO
(
ID_DEPARTAMENTO INT IDENTITY(1,1),
NOME_DEP VARCHAR(100)NOT NULL,
ID_FUNCAO INT ,
CONSTRAINT PK_DEP PRIMARY KEY (ID_DEPARTAMENTO),
CONSTRAINT PK_DEP_FUNCAO FOREIGN KEY (ID_FUNCAO)
REFERENCES FUNCAO (ID_FUNCAO)
)
USE PRESENCA1
CREATE TABLE FUNCAO
(
ID_FUNCAO INT IDENTITY(1,1),
NOME_FUNCAO VARCHAR(100)NOT NULL,
SALARIO VARCHAR(100)NOT NULL,
DATA VARCHAR(100) NOT NULL,
CONSTRAINT PK_FUNCAO PRIMARY KEY (ID_FUNCAO)
)
I’m using this device in Visual studio
INSERT INTO FUNCIONARIO (NOME_FUNCIONARIO,NOME_PAI,NOME_MAE,N_BI,DATA_NASC,GENERO,ESTA_CIVIL,FOTO,ID_DEPARTAMENTO ,ID_MUNICIPIO,DATA_HORA,USUARIO
The field Function name and Salary of the table Insert from the table official, but these two tables are foreign key in the table department and the table is foreign key in the table STAFF
These two fields have to be shown in the official table
Inserts the function, then inserts the department and then inserts the employee. Not only do it in the right order?
– Jéf Bueno