Write an SQL Query to Create An Employee table that can store more than 1 DepartmentID for each Emp

Posted by Kasani007 under Sql Server on 7/25/2014 | Points: 10 | Views : 1378 | Status : [Member] | Replies : 3
Write an SQL Query to Create An Employee table that can store more than 1 DepartmentID for each EmployeeId ?




Responses

Posted by: Vuyiswamb on: 7/25/2014 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
simple table should be


http://beyondrelational.com/quiz/sqlserver/tsql/2011/questions/human-resources-report.aspx

Thank you for posting at Dotnetfunda
[Administrator]

Kasani007, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: nayeemdotnetfunda-27597 on: 7/26/2014 [Member] Starter | Points: 25

Up
0
Down
create columns n store

Kasani007, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 7/30/2014 [Member] [MVP] Platinum | Points: 25

Up
0
Down

if you are asking for table structure, use below one to have multiple departments for an employee....

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[EmpDeptTab](
[EmployeeID] [int] NOT NULL,
[DepartmentID] [int] NOT NULL,
[Salary] [decimal](10, 2) NULL,
CONSTRAINT [PK_composite_EmpDept] PRIMARY KEY CLUSTERED
(
[EmployeeID] ASC,
[DepartmentID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

/* Data
EmployeeID DepartmentID Salary
1 10 300.00
1 20 500.00
2 10 100.00
3 20 150.00 */


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Kasani007, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response