score:1
Accepted answer
Usually you don't create one table with a column for category for these very reasons, that you can't have proper foreign keys.
You should create several tables.
One table to link Bills and GeneralArticles. Second table to link Bills and CalculatedArticles. Third table to link Bills and AdditionalRecords.
For the first link it may look like this (I didn't check the syntax):
CREATE TABLE BillsGeneralArticlesAssosiations(
[B_ID] [int] NOT NULL FOREIGN KEY REFERENCES Bill (B_ID) ,
[GA_ID] [int] NOT NULL FOREIGN KEY REFERENCES GeneralArticles (GA_ID)
CONSTRAINT [PK_BillsGeneralArticlesAssosiations] PRIMARY KEY CLUSTERED
(
[B_ID] ASC,
[GA_ID] ASC
))
Sometimes I add an IDENTITY
column ID
to this table as a primary key. Especially if there are other fields in this linking table.
More questions
- Foreign key constraint may cause cycles or multiple cascade paths?
- SQL DROP TABLE foreign key constraint
- How can I find out what FOREIGN KEY constraint references a table in SQL Server?
- How to remove foreign key constraint in sql server?
- How to alter table add column with named default constraint and named foreign key constraint?
- Entity Framework The ALTER TABLE statement conflicted with the FOREIGN KEY constraint
- Sql error on update : The UPDATE statement conflicted with the FOREIGN KEY constraint
- Operand type clash: int is incompatible with date + The INSERT statement conflicted with the FOREIGN KEY constraint
- How can I drop a table if there is a foreign key constraint in SQL Server?
- Introducing FOREIGN KEY constraint may cause cycles or multiple cascade paths. Specify on delete no action
- SQLAlchemy - don't enforce foreign key constraint on a relationship
- Could not drop object 'dbo.Table1' because it is referenced by a FOREIGN KEY constraint
- The INSERT statement conflicted with the FOREIGN KEY SAME TABLE constraint
- SQL Exception error #547 & Foreign Key constraint violations while attempting a delete
- Cannot truncate table because it is being referenced by a FOREIGN KEY constraint
- The ALTER TABLE statement conflicted with the FOREIGN KEY constraint
- Add a unique constraint of a sql table as foreign key reference to an another sql table
- Checking foreign key constraint "online"
- Bidirectional foreign key constraint
- Disable Foreign key constraint on a table?
- The INSERT statement conflicted with the FOREIGN KEY constraint error
- Disable Foreign Key Constraint Code First EF
- Foreign key constraint - how to delete referenced record?
- Execution plan oddity after re-enabling foreign key constraint
- Updating a Foreign Key constraint with ON DELETE CASCADE not updating?
- Composite Primary keys and Foreign key constraint error
- Correct syntax for foreign key constraint for multiple foreign keys
- MERGE statement conflicts with foreign key constraint
- Reference a foreign key and Add check constraint for column in parent table
- Why does creating a table with a foreign key constraint in one transaction block access to the referenced table in another?
More questions with similar tag
- SWAP Selected Rows in SQL Server
- SQL Server Stored Procedures Execution difference
- SSIS - connection to new database
- INSERT a row only with default or null values
- Alternative to Report Viewer for SQL Reporting Services
- Any other way to solve this query?
- Need to filter records from AUDIT table for a particular column
- SQL Update a table column with a sequence of values
- SQL Server decimal data type performance
- Exception handling important for the following code
- Randomly show three different questions per page load
- SQL query - Join that returns the first two records of joining table
- Need to generate rows with missing data in a large dataset - SQL
- Why does SQL Server allow this JOIN syntax?
- Recursive CTE of Dates Netezza SQL
- Sql Getting Top 2 results in each classification
- SQL Server xml copy values of one node to another
- MonoMac Console Application Returns Only First Character of nvarchar(max)
- SQL Group Multiple Results from Single Table
- iODBC error trying to connect to MS SQL Server in PHP with unixODBC/FreeTDS
- Slice a row containing time range into multiple rows (tricky sql question)
- reader writer deadlock in sql server
- database datatype performance: int or string
- Show visual diagram of tables and relations in Visual Studio Community 2015
- String concatenation with escaped variables
- SQL Distinct function din't work
- SQL Server Report Builder - How to aggregate rows of a group
- Import several values for procedure in SQL
- Currently using multiple left joins in SQL Server - is there an easier way?
- Paging in Common Table Value Expression(CTE), OFFSET/FETCH and Inner SELECT
Source:
stackoverflow.com