|
Jörgen Andersson wrote: If you make a join between an int and a varchar it wouldn't make a narrowing conversion on the varchar to int. It would make a widening conversion of the int to a varchar.
Nope - int has a higher precedence than varchar . If you try to join int to varchar , SQL will try to convert all values to int .
Data Type Precedence (Transact-SQL) | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
F*** me, you're right.
But why?
|
|
|
|
|
Comparing ints is faster, and probably seen as the default.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Yes, but a widening conversion to varchar and comparison between two varchars are probably faster than a narrowing conversion to int with an error check and then comparing two ints.
|
|
|
|
|
Jörgen Andersson wrote: with an error check and then comparing two ints. It's probably more a cast than a conversion.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
|
In fairness to Microsoft, they have introduced TRY_CAST() and TRY_CONVERT() in recent times which are very helpful when dealing with this kind thing.
98.4% of statistics are made up on the spot.
|
|
|
|
|
How about creating a foreign key relationship between the tables?
Would that not prevent this issue from happening again?
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
GuyThiebaut wrote: How about creating a foreign key relationship between the tables?
I believe that would trade one problem for another; you would trade an invalid cast for a foreign key constraint exception, which might well roll back a whole transaction. Moreover, who knows what it would do to the view?
David A. Gray
Delivering Solutions for the Ages, One Problem at a Time
Interpreting the Fundamental Principle of Tabular Reporting
|
|
|
|
|
Exactly, which is why foreign keys can be useful as they will prevent the insertion of data into a database which does not meet certain criteria.
A foreign key constraint should not affect a view - I see it more as a gatekeeper that prevents problematic data from being added to a database, whether that is by insertion, deletion or update.
I am aware that many people do not use foreign keys, however I have seen them to help in making the developer's life easier by keeping problematic data out of a database.
Without foreign keys you can find yourself in the position where the client is complaining about the system behaving strangely when the reason for that behaviour is, for want of a better word, unsanitised data.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
GuyThiebaut wrote: have seen them to help in making the developer's life easier by keeping problematic data out of a database.
I agree with you 100%, and I rely on foreign keys for precisely that reason. Nevertheless, I think it's important to be aware that having one doesn't excuse the developer from handling exceptions. In the situation under discussion, you are trading one kind of exception for another, albeit, more useful, one.
I don't think it would affect the view, either, but I thought it prudent to allow for some technical detail that I might have overlooked. I usually don't construct any views until I have my foreign keys defined, so that I can leverage them to help create the views.
David A. Gray
Delivering Solutions for the Ages, One Problem at a Time
Interpreting the Fundamental Principle of Tabular Reporting
|
|
|
|
|
static object s_obj = new object();
then in some function,
void func()
{
object obj = new object();
s_obj = obj;
}
Honestly, I have never seen such a code before. When someone does this, what actually happens to the memory, statically allocated to s_obj, initially? It's left hanging on the air without any reference ?
Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy Falcon.
|
|
|
|
|
Depending on garbage collection the memory should be released, because the ref counter of the original object is set to zero in the func() assigment.
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
Thanks, But does this apply even to Static Variables?
Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy Falcon.
|
|
|
|
|
Yes; the object ("new object") is not static; the pointer-variable holding that object is.
Once another object is assigned to it, the other object is no longer referenced.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy Falcon.
|
|
|
|
|
KarstenK wrote: the ref counter of the original object is set to zero
If it's .NET, there's no ref counter. Instead, the GC will detect that the object is no longer reachable. That way, circular references won't leak memory.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
From now on, I will use that as an insult. Isomorphic Git just sounds way better than poopy-head.
|
|
|
|
|
|
Nice. Exactly what I always wanted!
|
|
|
|
|
Yup. Sure beats sliced bread.
... such stuff as dreams are made on
|
|
|
|
|
I was thinking IoT Toaster. But that would work too!
|
|
|
|
|
|
Lol! That's what I am talking about!
|
|
|
|