I am trying to create a composite foreign key relationship/constraint. All tables are empty. I have this table:
CREATE TABLE [dbo].[ChemSampleValueTest](
[SampleNumber] [int] NOT NULL,
[ParameterID] [int] NOT NULL,
[Value] [numeric](18, 6) NOT NULL,
[Accuracy] [varchar](50) NULL,
[ResultGroupID] [int] NOT NULL,
[QAState] [nvarchar](32) NOT NULL,
CONSTRAINT [PK_SampleValueTest] PRIMARY KEY CLUSTERED
(
[SampleNumber] ASC,
[ParameterID] ASC,
[ResultGroupID] ASC
)
) ON [PRIMARY]
and this table:
CREATE TABLE [dbo].[ChemSampleValueEventLinkTest](
[Event] [int] NOT NULL,
[SampleNumber] [int] NOT NULL,
[ResultGroupID] [int] NOT NULL,
[ParameterID] [int] NOT NULL,
[QAState] [nvarchar](32) NULL
) ON [PRIMARY]
and I want to link them like this:
alter table [ChemSampleValueEventLinkTest] add
constraint FK_ChemSampleValueEvent_ChemSampleValue_test
foreign key ([SampleNumber], [ResultGroupID], [ParameterID])
references ChemSampleValueTest ([SampleNumber], [ResultGroupID], [ParameterID])
As far as I can tell all column types are the same, but it keeps on saying
There are no primary or candidate keys in the referenced table
'ChemSampleValueTest' that match the referencing column list in the foreign key
'FK_ChemSampleValueEvent_ChemSampleValue_test'.
Where am I going wrong?
It looks like you need to have your FK/references list in the same order they appear in the PK definition.
This should work:
CREATE TABLE [dbo].[ChemSampleValueTest](
[SampleNumber] [int] NOT NULL,
[ParameterID] [int] NOT NULL,
[Value] [numeric](18, 6) NOT NULL,
[Accuracy] [varchar](50) NULL,
[ResultGroupID] [int] NOT NULL,
[QAState] [nvarchar](32) NOT NULL,
CONSTRAINT [PK_SampleValueTest] PRIMARY KEY CLUSTERED
(
[SampleNumber] ASC,
[ParameterID] ASC,
[ResultGroupID] ASC
)
) ON [PRIMARY]
CREATE TABLE [dbo].[ChemSampleValueEventLinkTest](
[Event] [int] NOT NULL,
[SampleNumber] [int] NOT NULL,
[ResultGroupID] [int] NOT NULL,
[ParameterID] [int] NOT NULL,
[QAState] [nvarchar](32) NULL
) ON [PRIMARY]
alter table [ChemSampleValueEventLinkTest] add
constraint FK_ChemSampleValueEvent_ChemSampleValue_test
foreign key ([SampleNumber], [ParameterID], [ResultGroupID])
references ChemSampleValueTest ([SampleNumber], [ParameterID], [ResultGroupID])
Related
Here are my tables CREATE Statements:
CREATE TABLE `User` (
`UserId` int NOT NULL AUTO_INCREMENT,
`CompanyId` int NOT NULL,
`FirstName` varchar(50) NOT NULL,
`LastName` varchar(50) NOT NULL,
`UserName` varchar(100) NOT NULL,
PRIMARY KEY (`UserId`),
KEY `FK_Company_User_idx` (`CompanyId`),
CONSTRAINT `FK_Company_User` FOREIGN KEY (`CompanyId`) REFERENCES `Company` (`CompanyId`)
) ENGINE=InnoDB AUTO_INCREMENT=256 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
CREATE TABLE `Notification` (
`NotificationId` int NOT NULL AUTO_INCREMENT,
`Email` varchar(100) DEFAULT NULL,
`Message` text,
`Subject` varchar(100) DEFAULT NULL,
`UserId` int NOT NULL,
PRIMARY KEY (`NotificationId`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
I am trying to create a FK between UserId in Notification and UserId in User but the dropdown for selecting the field is not populating.
Any help is appreciated.
I am trying to export some records from ServerA.DatabaseA..Anchor to ServerB.DatabaseB..Anchor. The source is active. The destination is a development database. The destination has one additional field, a tenancy id.
SQL for Source table
CREATE TABLE [dbo].[Anchor](
[AnchorId] [int] IDENTITY(130,1) NOT NULL,
[NodeId] [int] NOT NULL,
[UnitName] [varchar](200) NOT NULL,
[SetPosition] [varchar](5) NOT NULL,
[CreateDate] [datetime] NOT NULL,
[StartDate] [datetime] NOT NULL,
[EndDate] [datetime] NOT NULL,
[Latitude] [float] NULL,
[Longitude] [float] NULL,
[RadiusMeters] [int] NOT NULL,
[Creator] [varchar](100) NULL,
[Cellnumber1] [varchar](20) NULL,
[Cellnumber2] [varchar](20) NULL,
[Cellnumber3] [varchar](20) NULL,
[EmailTo] [varchar](255) NULL,
[UseMsgFwdContacts] [bit] NOT NULL,
CONSTRAINT [PK_Anchor] PRIMARY KEY CLUSTERED
(
[AnchorId] 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
ALTER TABLE [dbo].[Anchor] ADD CONSTRAINT [DF_Anchor_UseMsgFwdContacts] DEFAULT ((0)) FOR [UseMsgFwdContacts]
GO
SQL Query for selecting records
Datetime's are cast to datetime for testing
SELECT [AnchorId]
,'MXM' as OrgCode -- the new tenancy field
,[NodeId]
,[UnitName]
,[SetPosition]
,CAST([CreateDate] as DATETIME) as [CreateDate]
,CAST([StartDate] as DATETIME) as [StartDate]
,CAST([EndDate] as DATETIME) as [EndDate]
,[Latitude]
,[Longitude]
,[RadiusMeters]
,[Creator]
,[Cellnumber1]
,[Cellnumber2]
,[Cellnumber3]
,[EmailTo]
,[UseMsgFwdContacts]
FROM [client_Maxam].[dbo].[Anchor]
WHERE AnchorId >335
Click Ok and Next, and now...
Why is my source datatype being picked up as datetime2, preventing me from running the export.
My question is similar to the one posted earlier in the Community. questions/62936399/error-sql-state-42703-while-trying-to-insert-data-into-my-table
In PostgreSQL, I'm trying to run CREATE Table Statement so that I can continue with inserting values. Although my CREATE statement fails so I can't get on with INSERT statement. The error message that keeps coming up ERROR: relation "eventrequest" does not exist
SQL state: 42P01
I have re-did the entire CREATE Statement twice although the error message does not change.
CREATE TABLE CUSTOMER
(CustNo VARCHAR(8) CONSTRAINT CustNoNotNull NOT NULL,
CustName VARCHAR(30) CONSTRAINT CustNameNotNull NOT NULL,
Address VARCHAR(50) CONSTRAINT AddressNotNull NOT NULL,
Internal CHAR(1) CONSTRAINT InternalNotNull NOT NULL,
Contact VARCHAR(35) CONSTRAINT ContractNotNull NOT NULL,
Phone VARCHAR(11) CONSTRAINT CPhoneNotNull NOT NULL,
City VARCHAR(30) CONSTRAINT CityNotNull NOT NULL,
State VARCHAR(2) CONSTRAINT StateNotNull NOT NULL,
Zip VARCHAR(10) CONSTRAINT ZipNotNull NOT NULL,
CONSTRAINT PK_CUSTOMER PRIMARY KEY (CustNo)
);
CREATE TABLE FACILITY
(FacNo VARCHAR(8) CONSTRAINT FacNoNotNull NOT NULL,
FacName VARCHAR(30) CONSTRAINT FacNameNotNull NOT NULL,
CONSTRAINT PK_FACILITY PRIMARY KEY (FacNo),
CONSTRAINT Unique_FacName UNIQUE(FacName)
);
CREATE TABLE LOCATION
(LocNo VARCHAR(8) CONSTRAINT LocNoNotNull NOT NULL,
FacNo VARCHAR(8),
LocName VARCHAR(30) CONSTRAINT LocNameNotNull NOT NULL,
CONSTRAINT PK_LOCATION PRIMARY KEY (LocNo),
CONSTRAINT FK_FACNO FOREIGN KEY (FacNo) REFERENCES FACILITY (FacNo)
);
CREATE TABLE EMPLOYEE
(
EmpNo CHAR(11) CONSTRAINT EmpNoNotNull NOT NULL,
EmpName VARCHAR(30) CONSTRAINT EmpNameNotNull NOT NULL,
Department VARCHAR(30) CONSTRAINT DepartmentNotNull NOT NULL,
Email VARCHAR(255) CONSTRAINT EmailNotNull NOT NULL,
Phone VARCHAR(30) CONSTRAINT PhoneNotNull NOT NULL,
CONSTRAINT PK_EMPLOYEE PRIMARY KEY (EmpNo)
);
CREATE TABLE EVENTPLAN
(
PlanNo VARCHAR(8) NOT NULL,
EventNo VARCHAR(8) NOT NULL,
workdate DATE NOT NULL,
notes VARCHAR(40),
activity VARCHAR(20) NOT NULL,
empno VARCHAR(8),
CONSTRAINT PK_PLANNO PRIMARY KEY (PlanNo),
CONSTRAINT FK_EVENTNO FOREIGN KEY (EventNo) REFERENCES EventRequest (EventNo)
);
CREATE TABLE EVENTREQUEST
(
EventNo VARCHAR(8) NOT NULL,
DateHeld DATE NOT NULL,
DateReq DATE NOT NULL,
FacNo VARCHAR(8) NOT NULL,
CustNo VARCHAR(8) NOT NULL,
DateAuth DATE,
Status VARCHAR(8) NOT NULL CHECK (Status IN ('Pending', 'Denied', 'Approved')),
EstCost DECIMAL(10, 2) NOT NULL,
EstAudience INT NOT NULL CHECK (EstAudience > 0),
BudNo VARCHAR(8),
CONSTRAINT PK_EVENTNO PRIMARY KEY (EventNo),
CONSTRAINT FK_FACILITYNOEVENTREQ FOREIGN KEY (FacNo) REFERENCES Facility (FacNo),
CONSTRAINT FK_CUSTOMERNO FOREIGN KEY (CustNo) REFERENCES Customer (CustNo)
);
CREATE TABLE EVENTPLANLINE
(
PlanNo CHAR(8) NOT NULL,
LineNo CHAR(8) NOT NULL,
LocNo CHAR(8) NOT NULL,
ResNo CHAR(8) NOT NULL,
TimeStart TIMESTAMP NOT NULL,
TimeEnd TIMESTAMP NOT NULL,
NumberFLD INTEGER NOT NULL,
CONSTRAINT PK_EVENTPLANLINE PRIMARY KEY (PlanNo, LineNo),
CONSTRAINT FK_EVENTPLAN FOREIGN KEY (PlanNo) REFERENCES EventPlan (PlanNo),
CONSTRAINT FK_LOCATION FOREIGN KEY (LocNo) REFERENCES Location (LocNo),
CONSTRAINT FK_RESOURCETBL FOREIGN KEY (ResNo) REFERENCES ResourceTbl (ResNo)
);
CREATE TABLE RESOURCETBL
(
ResNo CHAR(8) NOT NULL,
ResName VARCHAR(30) NOT NULL,
Rate DECIMAL(8, 2) NOT NULL,
CONSTRAINT PK_RESOURCETBL PRIMARY KEY (ResNo)
);
My source table, which is located in an Azure SQL Server Data Warehouse, has a column named Upline with the data type varbinary(1000). In the destination table, located in the same Azure SQL Server Data Warehouse, the data type and column name are the same. My issue is in the Azure Data Flow that is populating the destination table.
Instead of inserting the data into the sink table in the data flow, it is creating a new table in my data warehouse. Here is the create statement for the table that is being created with
CREATE TABLE [Common].[T_7be15bb497654f0c8eeb82459912f178]
(
[EmployeeSK] [int] NULL,
[EmployeeLastName] [nvarchar](max) NULL,
[EmployeeFirstName] [nvarchar](max) NULL,
[EmploymentStatus] [nvarchar](max) NULL,
[HireDate] [date] NULL,
[OriginalHireDate] [date] NULL,
[TerminationDate] [date] NULL,
[CurrentPosition] [nvarchar](max) NULL,
[PreviousPosition] [nvarchar](max) NULL,
[WorkAssignmentEffectiveStart] [date] NULL,
[Region] [nvarchar](max) NULL,
[District] [nvarchar](max) NULL,
[Site] [nvarchar](max) NULL,
[OnSiteDepartment] [nvarchar](max) NULL,
[DepartmentName] [nvarchar](max) NULL,
[ManagerDayForceEmployeeNumber] [nvarchar](max) NULL,
[Upline] [varbinary](max) NULL,
[Lvl] [int] NULL,
[dimStartDate] [date] NULL,
[dimEndDate] [date] NULL,
[dimIsCurrent] [int] NULL,
[dimHash] [nvarchar](max) NULL,
[r7ace46966877481a90d6f8039c6524b5] [int] NULL
)
As you can see from the picture (if you can see the picture), the table is giving the column Upline a varbinary(max) data type. Why is this happening? How can I stop it from happening? When I take this column out of the source and destination tables it works successfully. However, I need the column. The data flow has these activities: source, select, derived column, surrogate key, and sink. It is doing very simple stuff and the Upline is not being changed in the derived column.
Here is the error message from the pipeline that runs the data flow:
"Found an implicit conversion from VarBinary(Max) to VarBinary(1000) that requires ANSI truncation warning. This is not supported. Use the CONVERT function explicitly to execute this request." There is no convert function in the derived column activity so I can't do the suggestion it gives.
The max length of the data in the column is 24 (found using Select len(max(Upline))FROM [source table]).
Any help would be appreciated. Thanks.
I found a work around. In the create statement of the destination table I changed varbinary(1000) to be varbinary(max) and, at the end, I replaced this ending:
WITH
(
DISTRIBUTION = ROUND_ROBIN,
CLUSTERED COLUMNSTORE INDEX
)
GO
with this:
WITH
(
DISTRIBUTION = ROUND_ROBIN,
HEAP
)
GO
Now, the whole create statement looks like this:
CREATE TABLE [Common].[dimEmployee_temp]
(
[EmployeeSK] [int] IDENTITY(1,1) NOT NULL,
[DayForceEmployeeNumber] [nvarchar](255) NOT NULL,
[ConaEmployeeNumber] [char](10) NULL,
[EmployeeLastName] [nvarchar](255) NULL,
[EmployeeFirstName] [nvarchar](255) NULL,
[EmploymentStatus] [nvarchar](255) NULL,
[HireDate] [date] NULL,
[OriginalHireDate] [date] NULL,
[TerminationDate] [date] NULL,
[CurrentPosition] [nvarchar](255) NULL,
[PreviousPosition] [nvarchar](255) NULL,
[WorkAssignmentEffectiveStart] [date] NULL,
[Region] [nvarchar](255) NULL,
[District] [nvarchar](255) NULL,
[Site] [nvarchar](255) NULL,
[OnSiteDepartment] [nvarchar](255) NULL,
[DepartmentName] [nvarchar](255) NULL,
[UnionName] [nvarchar](255) NULL,
[ManagerDayForceEmployeeNumber] [nvarchar](255) NULL,
[Upline] [varbinary](max) NULL,
[Lvl] [int] NULL,
[dimStartDate] [date] NOT NULL,
[dimEndDate] [date] NULL,
[dimIsCurrent] [int] NOT NULL,
[dimHash] [nvarchar](256) NULL
)
WITH
(
DISTRIBUTION = ROUND_ROBIN,
HEAP
)
GO
This doesn't help me understand what is going on in the Azure data flow, but it does run successfully and insert into the table.
I need a relational database schema to store vCard ver 3 data elements.
Rather than reading the RFC and designing one from scratch, I'm looking to see if someone who has already done this is willing to share their database design.
(http://i.stack.imgur.com/61qGU.png)
This is my DB schema for a VCard 3.0. This works quite well with CardMe library, each type is mapped to a database table and the many-to-many / one-to-many relationships are enforced through foreign keys.
CREATE DATABASE ERP;
CREATE TABLE ERP.CONTACT_MAIL_ADDRESS
(
MAIL_ADDRESS_ID CHAR(36) NOT NULL,
POBOX VARCHAR(30),
EXTENDED_ADDRESS VARCHAR(255),
STREET VARCHAR(255) NOT NULL,
LOCALITY VARCHAR(50),
REGION VARCHAR(50),
POSTAL_CODE VARCHAR(30),
COUNTRY VARCHAR(50),
PRIMARY KEY(MAIL_ADDRESS_ID)
);
CREATE TABLE ERP.CONTACT_PHONE_NUMBER
(
PHONE_NUMBER_ID CHAR(36) NOT NULL,
LOCAL_NUMBER VARCHAR(255) NOT NULL, -- Free form telephone number
PRIMARY KEY(PHONE_NUMBER_ID)
);
CREATE TABLE ERP.CONTACT_EMAIL
(
EMAIL_ID CHAR(36) NOT NULL,
EMAIL_ADDRESS VARCHAR(255) NOT NULL,
PRIMARY KEY(EMAIL_ID)
);
CREATE TABLE ERP.CONTACT_AGENT
(
AGENT_ID CHAR(36) NOT NULL,
URI VARCHAR(255) NOT NULL,
PRIMARY KEY(AGENT_ID)
);
CREATE TABLE ERP.CONTACT_CATEGORIES
(
CATEGORY_ID CHAR(36) NOT NULL,
CATEGORY_NAME VARCHAR(255) NOT NULL,
PRIMARY KEY(CATEGORY_ID)
);
CREATE TABLE ERP.CONTACT_NOTE
(
NOTE_ID CHAR(36) NOT NULL,
NOTE TEXT NOT NULL,
PRIMARY KEY(NOTE_ID)
);
CREATE TABLE ERP.CONTACT_XTENDED
(
XTENDED_ID CHAR(36) NOT NULL,
XNAME VARCHAR(255) NOT NULL,
XVALUE VARCHAR(255) NOT NULL,
PRIMARY KEY(XTENDED_ID)
);
CREATE TABLE ERP.CONTACT_KEYS
(
KEY_ID CHAR(36) NOT NULL,
KEY_DATA TEXT NOT NULL,
PRIMARY KEY(KEY_ID)
);
CREATE TABLE ERP.CONTACT_DATA
(
CONTACT_DATA_ID CHAR(36) NOT NULL,
DATA_NAME VARCHAR(10) NOT NULL, -- [LOGO,PHOTO,SOUND]
URL VARCHAR(255),
INLINE CHAR(1),
DATA MEDIUMBLOB,
PRIMARY KEY(CONTACT_DATA_ID)
);
CREATE TABLE ERP.CONTACT_TYPES
(
TYPE_ID CHAR(36) NOT NULL,
TYPE_NAME VARCHAR(20) NOT NULL,
PRIMARY KEY(TYPE_ID)
);
CREATE TABLE ERP.CONTACT_ENCODING_TYPES
(
ENCODING_TYPE_ID CHAR(36) NOT NULL,
TYPE_NAME VARCHAR(20) NOT NULL,
PRIMARY KEY(ENCODING_TYPE_ID)
);
CREATE TABLE ERP.CONTACT
(
CONTACT_ID CHAR(36) NOT NULL,
FN VARCHAR(255) NOT NULL,
N VARCHAR(255) NOT NULL,
NICKNAME VARCHAR(255),
BDAY TIMESTAMP,
MAILER VARCHAR(50),
TZ INTEGER, -- Time zone offset in hours
GEO_LAT DOUBLE, -- Latitude
GEO_LONG DOUBLE, -- Longitude
TITLE VARCHAR(50),
ROLE VARCHAR(50),
PROD_ID VARCHAR(255),
REV VARCHAR(50),
SORT_STRING VARCHAR(50),
UID VARCHAR(255),
URL VARCHAR(255),
VERSION VARCHAR(10),
CLASS VARCHAR(50),
PRIMARY KEY(CONTACT_ID)
);
CREATE TABLE ERP.CONTACT_REL_MAIL_ADDRESS
(
CONTACT_ID CHAR(36) NOT NULL,
MAIL_ADDRESS_ID CHAR(36) NOT NULL,
FOREIGN KEY(CONTACT_ID) REFERENCES ERP.CONTACT(CONTACT_ID),
FOREIGN KEY(MAIL_ADDRESS_ID) REFERENCES ERP.CONTACT_MAIL_ADDRESS(MAIL_ADDRESS_ID),
PRIMARY KEY(CONTACT_ID,MAIL_ADDRESS_ID)
);
CREATE TABLE ERP.CONTACT_REL_PHONE_NUMBER
(
CONTACT_ID CHAR(36) NOT NULL,
PHONE_NUMBER_ID CHAR(36) NOT NULL,
FOREIGN KEY(CONTACT_ID) REFERENCES ERP.CONTACT(CONTACT_ID),
FOREIGN KEY(PHONE_NUMBER_ID) REFERENCES ERP.CONTACT_PHONE_NUMBER(PHONE_NUMBER_ID),
PRIMARY KEY(CONTACT_ID,PHONE_NUMBER_ID)
);
CREATE TABLE ERP.CONTACT_REL_EMAIL
(
CONTACT_ID CHAR(36) NOT NULL,
EMAIL_ID CHAR(36) NOT NULL,
FOREIGN KEY(CONTACT_ID) REFERENCES ERP.CONTACT(CONTACT_ID),
FOREIGN KEY(EMAIL_ID) REFERENCES ERP.CONTACT_EMAIL(EMAIL_ID),
PRIMARY KEY(CONTACT_ID,EMAIL_ID)
);
CREATE TABLE ERP.CONTACT_REL_CATEGORIES
(
CONTACT_ID CHAR(36) NOT NULL,
CATEGORY_ID CHAR(36) NOT NULL,
FOREIGN KEY(CONTACT_ID) REFERENCES ERP.CONTACT(CONTACT_ID),
FOREIGN KEY(CATEGORY_ID) REFERENCES ERP.CONTACT_CATEGORIES(CATEGORY_ID),
PRIMARY KEY(CONTACT_ID,CATEGORY_ID)
);
CREATE TABLE ERP.CONTACT_REL_NOTE
(
CONTACT_ID CHAR(36) NOT NULL,
NOTE_ID CHAR(36) NOT NULL,
FOREIGN KEY(CONTACT_ID) REFERENCES ERP.CONTACT(CONTACT_ID),
FOREIGN KEY(NOTE_ID) REFERENCES ERP.CONTACT_NOTE(NOTE_ID),
PRIMARY KEY(CONTACT_ID,NOTE_ID)
);
CREATE TABLE ERP.CONTACT_REL_DATA
(
CONTACT_ID CHAR(36) NOT NULL,
CONTACT_DATA_ID CHAR(36) NOT NULL,
FOREIGN KEY(CONTACT_ID) REFERENCES ERP.CONTACT(CONTACT_ID),
FOREIGN KEY(CONTACT_DATA_ID) REFERENCES ERP.CONTACT_DATA(CONTACT_DATA_ID),
PRIMARY KEY(CONTACT_ID,CONTACT_DATA_ID)
);
CREATE TABLE ERP.CONTACT_REL_AGENT
(
CONTACT_ID CHAR(36) NOT NULL,
AGENT_ID CHAR(36) NOT NULL,
FOREIGN KEY(CONTACT_ID) REFERENCES ERP.CONTACT(CONTACT_ID),
FOREIGN KEY(AGENT_ID) REFERENCES ERP.CONTACT_AGENT(AGENT_ID),
PRIMARY KEY(CONTACT_ID,AGENT_ID)
);
CREATE TABLE ERP.CONTACT_REL_KEYS
(
CONTACT_ID CHAR(36) NOT NULL,
KEY_ID CHAR(36) NOT NULL,
FOREIGN KEY(CONTACT_ID) REFERENCES ERP.CONTACT(CONTACT_ID),
FOREIGN KEY(KEY_ID) REFERENCES ERP.CONTACT_KEYS(KEY_ID),
PRIMARY KEY(CONTACT_ID,KEY_ID)
);
CREATE TABLE ERP.CONTACT_REL_XTENDED
(
CONTACT_ID CHAR(36) NOT NULL,
XTENDED_ID CHAR(36) NOT NULL,
FOREIGN KEY(CONTACT_ID) REFERENCES ERP.CONTACT(CONTACT_ID),
FOREIGN KEY(XTENDED_ID) REFERENCES ERP.CONTACT_XTENDED(XTENDED_ID),
PRIMARY KEY(CONTACT_ID,XTENDED_ID)
);
CREATE TABLE ERP.CONTACT_MAIL_ADDRESS_REL_TYPES
(
MAIL_ADDRESS_ID CHAR(36) NOT NULL,
TYPE_ID CHAR(36) NOT NULL,
FOREIGN KEY(MAIL_ADDRESS_ID) REFERENCES ERP.CONTACT_MAIL_ADDRESS(MAIL_ADDRESS_ID),
FOREIGN KEY(TYPE_ID) REFERENCES ERP.CONTACT_TYPES(TYPE_ID),
PRIMARY KEY(MAIL_ADDRESS_ID,TYPE_ID)
);
CREATE TABLE ERP.CONTACT_PHONE_NUMBER_REL_TYPES
(
PHONE_NUMBER_ID CHAR(36) NOT NULL,
TYPE_ID CHAR(36) NOT NULL,
FOREIGN KEY(PHONE_NUMBER_ID) REFERENCES ERP.CONTACT_PHONE_NUMBER(PHONE_NUMBER_ID),
FOREIGN KEY(TYPE_ID) REFERENCES ERP.CONTACT_TYPES(TYPE_ID),
PRIMARY KEY(PHONE_NUMBER_ID,TYPE_ID)
);
CREATE TABLE ERP.CONTACT_EMAIL_REL_TYPES
(
EMAIL_ID CHAR(36) NOT NULL,
TYPE_ID CHAR(36) NOT NULL,
FOREIGN KEY(EMAIL_ID) REFERENCES ERP.CONTACT_EMAIL(EMAIL_ID),
FOREIGN KEY(TYPE_ID) REFERENCES ERP.CONTACT_TYPES(TYPE_ID),
PRIMARY KEY(EMAIL_ID,TYPE_ID)
);
CREATE TABLE ERP.CONTACT_NOTE_REL_TYPES
(
NOTE_ID CHAR(36) NOT NULL,
TYPE_ID CHAR(36) NOT NULL,
FOREIGN KEY(NOTE_ID) REFERENCES ERP.CONTACT_NOTE(NOTE_ID),
FOREIGN KEY(TYPE_ID) REFERENCES ERP.CONTACT_TYPES(TYPE_ID),
PRIMARY KEY(NOTE_ID,TYPE_ID)
);
CREATE TABLE ERP.CONTACT_KEY_REL_TYPES
(
KEY_ID CHAR(36) NOT NULL,
TYPE_ID CHAR(36) NOT NULL,
FOREIGN KEY(KEY_ID) REFERENCES ERP.CONTACT_KEYS(KEY_ID),
FOREIGN KEY(TYPE_ID) REFERENCES ERP.CONTACT_TYPES(TYPE_ID),
PRIMARY KEY(KEY_ID,TYPE_ID)
);
CREATE TABLE ERP.CONTACT_DATA_REL_TYPES
(
CONTACT_DATA_ID CHAR(36) NOT NULL,
TYPE_ID CHAR(36) NOT NULL,
FOREIGN KEY(CONTACT_DATA_ID) REFERENCES ERP.CONTACT_DATA(CONTACT_DATA_ID),
FOREIGN KEY(TYPE_ID) REFERENCES ERP.CONTACT_TYPES(TYPE_ID),
PRIMARY KEY(CONTACT_DATA_ID,TYPE_ID)
);
CREATE TABLE ERP.CONTACT_DATA_REL_ENCODING_TYPES
(
CONTACT_DATA_ID CHAR(36) NOT NULL,
ENCODING_TYPE_ID CHAR(36) NOT NULL,
FOREIGN KEY(CONTACT_DATA_ID) REFERENCES ERP.CONTACT_DATA(CONTACT_DATA_ID),
FOREIGN KEY(ENCODING_TYPE_ID) REFERENCES ERP.CONTACT_ENCODING_TYPES(ENCODING_TYPE_ID),
PRIMARY KEY(CONTACT_DATA_ID,ENCODING_TYPE_ID)
);