Sql设计用于员工详细信息和薪资表。员工代码不在员工详细信息中重复,并找到salry,员工姓名,名称

时间:2014-03-06 06:40:32

标签: sql-server tsql

我希望如何通过这两个表获取员工薪资信息和EMPLOYEE_CODE,FIRST_NAME,我希望员工ramesh薪水等员工的工资是1000 rs ..以及员工代码中TBL_BASIC_SALARY的变化。

TBL_ADDNEW_EMPLOYEE HERE EMPLOYEE INFORMATION 
EMPLOYEE_ID IS PRIMARY KEY

EMPLOYEE_ID int 
EMPLOYEE_CODE   varchar(200)=NULL

FIRST_NAME  varchar(200)=NULL

LAST_NAME   varchar(200)=NULL

USER_NAME   varchar(400)=NULL

FATHER_NAME varchar(200)=NULL

MOTHER_NAME varchar(200)=NULL

GENDER  varchar(50)=NULL
DEPARTMENT  varchar(200)=NULL

DESIGNATION varchar(200)=NULL

PROFILE_PIC varchar(200)=NULL

ADDRESS varchar(200)=NULL


SECOND TABLE TBL_BASIC_SALARY 

WHERE SALARY_ID IS PRIMARY KEYS

SALARY_ID   int 

BASIC_SALARY decimal(18, 0)=NULL

SALARY_TYPE varchar(50)=NULL


AND  ADD INFORMATION DETAILS OF EMPLOYEE AND EMPLOYEE_CODE ARE UNIQUE FOR EVERY EMPLOYEE

ALTER PROCEDURE [dbo].[USP_ADDNEW_EMPLOYEE]
  -- Add the parameters for the stored procedure here

  @EMPLOYEE_CODE                VARCHAR(200)=NULL,

  @FIRST_NAME                   VARCHAR(200)=NULL,

  @LAST_NAME                    VARCHAR(200)=NULL,

  @USER_NAME                    VARCHAR(400)=NULL,

  @FATHER_NAME                  VARCHAR(200)=NULL,

  @MOTHER_NAME                  VARCHAR(200)=NULL,

  @GENDER                      VARCHAR(200)=NULL,

  @DEPARTMENT                   VARCHAR(200)=NULL,

  @DESIGNATION                  VARCHAR(200)=NULL,

  @PROFILE_PIC                  VARCHAR(200)=NULL,

  @FILENAME                      VARCHAR(500)=NULL,

  @FILE_EXTENSION                VARCHAR(10)=NULL,

    enter code here

  @ADDRESS               VARCHAR(200)=NULL,

BEGIN
   --*********FOR ADD PRODUCTS INFORMATION***************************************************------ 


    Declare @CurrentID varchar(500)
    Declare @NewFileName VARCHAR(500)
   IF(@Calltype='ADD_EMPLOYEE_INFO')
  BEGIN

   IF EXISTS(SELECT EMPLOYEE_ID FROM TBL_ADDNEW_EMPLOYEE where EMPLOYEE_CODE=@EMPLOYEE_CODE)
  BEGIN 
    SELECT 1 AS SUCCESS
    END
ELSE
   BEGIN
       INSERT INTO TBL_ADDNEW_EMPLOYEE
       (
       EMPLOYEE_CODE,FIRST_NAME,LAST_NAME,FATHER_NAME,MOTHER_NAME,GENDER,DEPARTMENT,
       DESIGNATION,PROFILE_PIC,ADDRESS,
          )

       VALUES
       (
       @EMPLOYEE_CODE,@FIRST_NAME,@LAST_NAME,@FATHER_NAME,@MOTHER_NAME,@GENDER,@DEPARTMENT,
       @DESIGNATION,@PROFILE_PIC,@ADDRESS,
       )

    SET @CurrentID=(SELECT @@IDENTITY)  
    SET @NewFileName=@FILENAME+'_'+@CurrentID +'.'+@FILE_EXTENSION  

    UPDATE TBL_ADDNEW_EMPLOYEE SET PROFILE_PIC=@NewFileName
    WHERE EMPLOYEE_ID=@CurrentID                

       SELECT @NewFileName AS SCUCESS 
     END
  END

我希望如何通过这两个表获取员工薪资信息和EMPLOYEE_CODE,FIRST_NAME,我希望员工ramesh薪水等员工的工资是1000 rs ..以及员工代码中TBL_BASIC_SALARY的变化。

1 个答案:

答案 0 :(得分:0)

目前TBL_ADDNEW_EMPLOYEETBL_BASIC_SALARY之间没有映射,因此您可以根据自己的要求实施映射...

  1. TBL_BASIC_SALARY表格中,添加EMPLOYEE_ID列并使用TBL_ADDNEW_EMPLOYEE创建外键约束。

  2. 第二个您可以创建一个新的关联表并添加EMPLOYEE_IDSALARY_ID列,并为这两个表创建外键约束。在插入数据时,您必须将两个表的@@IDENTITY插入到这个新的关联表中。

  3. 现在使用SQL连接来检索结果。