New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Foreign key can be created on field with different types then referenced table - this should not be possible [CORE4039] #4369
Comments
Commented by: @dyemanov Out of curiosity, what practical problems do you see here? The SQL specification says that the declared type of each referencing column shall be comparable to the declared type of the corresponding referenced column. INT and SMALLINT are perfectly comparable, I'd say. |
Modified by: @dyemanovVersion: 2.5.3 [ 10461 ] => |
Commented by: @livius2 Only clarity of data and waste of db space you know that you never can insert in colum ID_AAA data bigger then smallint and extream sample (of course i never see varchar size reference like this but..) wasting 900 bytes CREATE TABLE AAAA CREATE TABLE BBBB commit; alter table bbbb |
Commented by: @livius2 and try this in exchanged field types ID from referenced table is bigger field size than can be stored CREATE TABLE AAA CREATE TABLE BBB commit; alter table bbb |
Commented by: @dyemanov Index keys for ints and smallints are of the same size, both index keys and records are compressed. Thus I don't see problems with wasted db space. |
Commented by: @aafemt I would suggest different example: create table master (id varchar(3) primary key); Varchar and integer are comparable. |
Commented by: @mrotteveel Why should that be impossible? It may be nonsensical in this case (as you are actually restricting ID_AAA to values in a SMALLINT), but it will work and not result in problems or errors. |
Commented by: @livius2 >>Dmitry Yemanov MSSQL run into error |
Commented by: Sean Leyne (seanleyne) Karol, the fact MS SQL considers it to be an error does not mean that Firebird can not use an approach which is more forgiving. |
Modified by: Sean Leyne (seanleyne)status: Open [ 1 ] => Resolved [ 5 ] resolution: Won't Fix [ 2 ] |
Commented by: @livius2 I know that MSSQL is not determinant CREATE TABLE AAA CREATE TABLE BBB commit; alter table bbb |
Commented by: @asfernandes You can assign/compare variables of different types, so not everything is extremely strict. |
Modified by: @pcisarstatus: Resolved [ 5 ] => Closed [ 6 ] |
Commented by: @livius2 i can undarstand that someone can need this from some reason, i see in my life many strange but working solution and this is ok. my question is now is possible to have config option for this settings? i beleve that only 1%% of developers will need this option to be turned off |
Commented by: @dyemanov We don't add config options for such reasons. |
Commented by: @asfernandes This is a job for a "schema analyzer" tool. I don't know if a tool like this exists for Firebird. |
Submitted by: @livius2
CREATE TABLE AAA
(
ID SMALLINT NOT NULL PRIMARY KEY
);
CREATE TABLE BBB
(ID SMALLINT NOT NULL PRIMARY KEY,
ID_AAA INTEGER
);
commit;
alter table bbb
add FOREIGN KEY(ID_AAA) REFERENCES AAA(ID) ON UPDATE CASCADE ON DELETE NO ACTION;
------------------------------------
as you see we was created field reference between smallint and integer - this should not be possible
The text was updated successfully, but these errors were encountered: