Recent Entries 10
- snippet minor 112d agoHow to write an SQL query where the count of 2 different attributes is the same?I created two different tables and then decided to put them (=) to each other however, what I am confused about is whether (=) is allowed to be used like that. I tried using IN but I didn't know where to go from there either. Is what I did correct? Consider a relational schema for storing information related to movies: ActorMovie(a_name, a_YofB, m_title, m_year) Movie(title, year, genre, budget, cost, gross_earnings) Q: List the names of all actors who acted in an equal number of comedies and tragedies. ``` Create View V1 AS ( Select name From ActorMovie a, Movie m Where a.m_title = m.title AND a.m_year = m. year AND Genre = ‘Comedy’) Create View V2 ( Select name From ActorMovie a, Movie m Where a.m_title = m.title AND a.m_year = m. year AND Genre = ‘Tragedies’) Select COUNT (name) = (Select Count (name) FROM V2) From V1 ```
- snippet minor 112d agoHow do databases guarantee that two transactions with different isolation levels run concurrently correctlyI wonder how databases guarantee that two transactions with different isolation levels run concurrently correctly. That is, different sessions are allowed to use different isolation levels. For example, one session may use "serializable" and the other may use "read committed". How do databases guarantee that two transactions with different isolation levels run concurrently correctly? I tried to google this topic but could not find any material explaining this topic in detail.
- pattern minor 112d agoRead-only transaction anomalyI've learned about this anomaly from these papers: https://www.cs.umb.edu/~poneil/ROAnom.pdf (original) https://johann.schleier-smith.com/blog/2016/01/06/analyzing-a-read-only-transaction-anomaly-under-snapshot-isolation.html (short and easy explanation) Can somebody please explain why is this considered an anomaly? AFAIK, a read-only transaction should see committed changes at the time of its execution, so the result is correct.
- debug minor 112d agoWhy intended integrity constraint cannot be enforced?What does the following integrity constraint try to enforce? (integrity constraint is primary key and check in this case but I couldn't understand what I should really write). Explain why the intended integrity constraint cannot be enforced? ``` CREATE TABLE Sailors ( sid INTEGER, sname CHAR(10), rating INTEGER, age REAL, PRIMARY KEY (sid), CHECK ( (SELECT COUNT (S.sid) FROM Sailors S) + (SELECT COUNT (B.bid) FROM Boats B) < 100 ) ) ; ``` We are studying SQL at school. Sabancı bilgisayara selamlar @yguney
- pattern minor 112d agoDesign for CE Events / Training DatabaseI'm working on a design for a continuing education training database. Users will register for a CE course/event that could be one day or multiple days. Courses are taught multiple times per year. The part I wanted some review on is the calendar part of the DB. Here is the design criteria: - Multiple events taught on varying schedules throughout the year. - Classes/Events can be part of a day, one day or multiple days. - Times can be different across days for the same Instance. Ex. "Summer xyz Training" held 9am-5pm Monday, 9-noon Tuesday, etc. Here is my design for this part of the DB so far: Event Class, event or course... can be scheduled multiple times... taught at various times, dates, and locations repeating throughout the year. - `Event_ID` - Could be called `Class_ID`. Could be class or event. I went with `Event_ID` to handle either. - `Name` - Ex. "xyz Training" - `Description` - - `Objectives` - yes - hidden - `Outline` - yes - hidden - `Duration_hours` ( Break up by Class Schedule ) - `Notes` - Hidden from user Event_Instance Instance of an event. Can be across multiple days. `Event_Instance_Schedule` for the Instance must add up to `Event.Duration_Hours` - `Event_Instance_ID` - `Location_ID` - Tie to Location table for where (could be physical or on line) - `Description` - Ex. "Summer xyz training" Event_Instance_Schedule Block of time as part of `Event_Instance` that adds to total `Duration_Hours`. - `Event_ID` - `Event_Instance_ID` - - `Event_Instance_Schedule_ID` - `Instructor_ID`? - `Start_Date_Time` - Ex. "1/1/2017 8am" - `End_Date_Time` - Ex. "1/1/2017 5pm" - `Notes` I don't really need to setup Google Calendar type re-occurrence, thankfully. My thinking was that the user chooses a class, gives that instance a title like "Summer xyz training", and then schedules times until they reach the `Duration_hours` number. I think it's fairly simple. Just looking for feedback or "have you thought about this... " feedba
- pattern major 112d agoDoes any DBMS have a collation that is both case-sensitive and accent-insensitive?Note this question is vendor/version agnostic It seems to me, as a speaker (typist, writer) of English, reasonable to expect words to be properly cased but not necessarily have the correct accents going in the right direction: as I mused in a tete-a-tete with Chloe the maitre d'hotel at the Champs-Elysees restaurant, while waiting for the garcon to fetch my sauted jalapeno pate... You get the idea with that. So today I thought I wanted a search condition to use a case-sensitive but accent-insensitive collation but couldn't find one. Is there a good reason for this or is mine merely a rare use case? Here's an example of some documentation I was looking at (though thinking vendor/version agnostic): SQL Server Collation Name (SQL Server 2008 R2)
- snippet moderate 112d agoConvert a date range to an interval descriptionA requirement in a recent project was to report when a resource would be fully consumed. As well as the exhaustion calendar date I was asked to show the remaining time in English-like format, something like "1 year, 3 months to go." The built-in `DATEDIFF` function Returns the count ... of the specified datepart boundaries crossed between the specified startdate and enddate. If used as-is this could produce misleading or confusing results. For example, using an interval of YEAR would show 1999-12-31 (YYYY-MM-DD) and 2000-01-01 to be one year apart whereas common sense would say these dates are separated by only 1 day. Conversely using an interval of DAY 1999-12-31 and 2010-12-31 are separated by 4,018 days while most people would see "11 years" as a better description. Starting from the number of days and calculating months and years from there would be prone to leap year and size-of-month errors. I got to wondering how this could be implemented in the various SQL dialects? Example output includes: ``` create table TestData( FromDate date not null, ToDate date not null, ExpectedResult varchar(100) not null); -- exact formatting is unimportant insert TestData (FromDate, ToDate, ExpectedResult) values ('1999-12-31', '1999-12-31', '0 days'), ('1999-12-31', '2000-01-01', '1 day'), ('2000-01-01', '2000-02-01', '1 month'), ('2000-02-01', '2000-03-01', '1 month'), -- month length not important ('2000-01-28', '2000-02-29', '1 month, 1 day'), -- leap years to be accounted for ('2000-01-01', '2000-12-31', '11 months, 30 days'), ('2000-02-28', '2000-03-01', '2 days'), ('2001-02-28', '2001-03-01', '1 day'), -- not a leap year ('2000-01-01', '2001-01-01', '1 year'), ('2000-01-01', '2011-01-01', '11 years'), ('9999-12-30', '9999-12-31', '1 day'), -- catch overflow in date calculations ('1900-01-01', '9999-12-31', '8099 years 11 month
- pattern major 112d agoIf a person's name is Null then how would it break the database?I was reading this article on BBC. It tells a story of a person named Jenifer Null and how she faces day to day problems while using online databases like booking plane tickets, net banking etc. I am not well versed in databases and I do not use it very often. When I made a website for learning, the server side form validation used regular expressions. From what I remember it would happily accept the name "Null". I have not tried it though. Could someone explain the technicalities when this situation would occur? Is the form validation just doing a `string == NULL` or something? Even so I do not think `NULL is same as "NULL"`.
- pattern minor 112d agoIs there any scenario where the existence of one or more Indexes in a table can prejudice it?The title sums it up. I've learned and always heard that indexes in tables improve CRUD operations. A developer that I met last weekend told me that he does not like Indexes because they are bad - yes, "bad" does not clarify anything but we did not had time to discuss it further (we were at a party). Anyway, maybe because my lack of experience, I do not know of a scenario where Indexes can cause troubles during CRUD operations, but maybe there are a few out there. I'm asking this question to know if there are any...
- pattern minor 112d agoRelational Model Design - Entity with one attributeI am trying to design a database relational model for an assignment. First, I design the ER diagram, and then the relational model with tables (schemas). Here's my question: Is it possible for an entity to have only one attribute? To put a bit more to this: is it possible or logical to come to a relation with a single attribute in the course of decomposition? If that happens, and is accepted, how should one proceed?