March 24, 2014 at 12:25 pm
Hi there,
I have Company information such as
CompanyNo, Company Name, Address,Num of Employees. I also have details about what economic activities the company does. Eg: Whole sale, Agriculture, Other retail sale of new goods in specialized stores,Renting and operating of own or leased real estate etc.
A company can have many economic activities.
So, how can make it into a relational db table?? Should I create a reference table such as Economic_Activities
CREATE TABLE [dbo].[Economic_Activities](
[ID] [varchar](10) NOT NULL,
[Description] [nvarchar](1000) NULL,
CONSTRAINT [PK_Economic_Activities_ID] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
How do I link the Company table to this? Do I need a third table to link Company table to Economic_Activities??
Thanks
Rash
March 24, 2014 at 12:32 pm
Sounds like you need 3 tables:
Company (CompanyID INT IDENTITY(1,1) PRIMARY KEY...)
EconActivity(EconActivityID INT IDENTITY(100000,1) PRIMARY KEY...)
CREATE TABLE CompanyActivity(
CompanyID INT,
EconActivityID INT,
...
PRIMARY KEY (CompanyID, EconActivityID)
FOREIGN KEY CompanyID REFERENCES Company(CompanyID),
FOREIGN KEY EconActivityID REFERENCES EconActivity(EconActivityID));
March 25, 2014 at 3:25 am
The Stairway to Database Design here on SSC should be a good read for you.
http://www.sqlservercentral.com/articles/Stairway+Series/70199/
March 25, 2014 at 8:39 am
Good article! Thanks
March 25, 2014 at 8:43 am
I didn't write it 🙂 ... but you are very welcome.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply