Feedback for SQL DB Design - sql

I'm trying to design a database for an application where users can submit and take tests.
Here is what I got so far:
http://i.stack.imgur.com/pgf7m.png
I'm particularly unsure about the relation between Test_Testee and QuestionAnswer_TesteeAnswer. I need a way to connect the answers & the questions & the tests, but I'm afraid the solution I came up with is a bit naive.
If you can see anything wrong with my design, or if you would do something different please say so, I'm just looking for some general feedback.
Thanks!

It feels a little off.
The testee should take the test (one or more times) - possibly as shown in test_testee.
for each taking of the test, the testee should have 0 or 1 answers to each question:
this is a link between test_testee and question that includes the given answer... one table.

Related

Postgres - DB Design & Spring-Data-JPA query related suggestion required

Hello Friends,
I have a kind of requirement like, Student & Question are entities.
Both Entity are in many-to-many relation.
I would like to represent my idea is something likewise(refer below screen-shot. please correct me if any improvement is possible).
I would like to know from you guys is that,
1) is the above mentioned DB-design is good ? is there any improvement
then let me know.
And second one is related to query(JPQL),
2) it's most important, in spring-data-jpa, how would I implement in
such a way so that, even though user has not answered question then
also, those question needs to reflect under user-profile page that
this question is still not answered. Refer below screen-shot about
an expectation of this(second one) question.
Any help would be really appreciable!!

Data migration concept in databases

i have a generic question about data migration/conversion.
here the situation:
i have data in a access db and want to migrate it into a oracle db. its not a 1 to 1 migration. i need to define which data should be imported into a specific oracle table and create some logic after that somehow.
do you have some ideas or a concept how to do this? maybe a checklist not that i forget something or i dont know.
Thank you.
Are you going to run it just once and be done? Or do you need to set up a job that routinely transfers the data? The keyword you might not be familiar with for googling is "ETL" - Extract, Transform, Load - and there are lots of products designed to handle ETL tasks.
Common sticking points are converting dates from one db to another and floating point numbers (especially currency.) When you hit specific problems, post new questions. There's a stackoverflow sister site, serverfault.com that might be a better fit for a lot of ETL questions. The products you're working with are popular so the db experts there are likely to have quick answers on datatype issues.

SQL Server Back End, Front End?

Ok so this is my first question on this site so please bear with me.
My problem is that our company is currently changing from access to an SQL database back end and I was given the job to design a front-end for non programmer users to just pull pre-defined queries or build a query of their own by just selecting the fields they want (dynamic query).
What I want to know is what would be the simplest way to go about doing this due to the fact that I have a some programming background but I wouldn't say I'm an advanced programmer.
I've done some searching over the last couple days and came across things such as Ruby on Rails and phpMyAdmin however before I take on the task of learning how to program with these tools I want to know for sure if I am going in the right direction before wasting my time on a pointless endeavor.
I've seen similar questions even on this site however none truly gave the answer I was looking for; any help will be much appreciated.
Also would it be easier to make this web-based?

COPY CSV files, then analyze? step by step?

I just started to upload CSV files and creating tables in the database of the company I work for. Would anyone be so kind to explain the proper steps to ensure the copy was complete and there are no mistakes?
My boss told me a few steps of how they do things:
CREATE TABLE -> COPY
or
INSERT DATA -> CREATE INDEX/CONSTRAINTS (if necessary) -> TABLE ANALYSIS
The table analysis part is the confusing part for me. They told me to analyze the table, then check for errors, then get the estimate rows. What do I do with the estimate rows? I used ANALYZE table_name but nothing really shows on the data output.
Please help!
My answer is going to take a slightly different tack.
Clearly your boss has given you instructions and you don't understand them. In my opinion it is important that you go back to your boss and keep asking questions until you understand.
There are a number of important reasons for this:
1. You understand what you are being asked to do (rather than us guessing).
2. If it goes wrong you have done what you were asked, and
3. You might learn something.
The attitude that asking questions ("asking noob questions again") makes you look stupid or ignorant is very dangerous and will, in fact, make you stupid and ignorant.
After 30 years developing some very complex software systems, I still ask questions whenever I don't understand something. The result? In the end, I understand.
This is the only way to actually get better. None of us was born knowing how to do everything.
This sounds like a big misunderstanding. Your boss probably just wants you to run
ANALYZE table_name;
for every table to update the statistics (including row estimates). The query planner uses those statistics to chose how to best execute queries. Read the fine manual about ANALYZE.
Better ask your boss next time if you don't understand instructions.
Typically you'll want to check for a few things
The number of rows inserted is consistent
Data Types are sufficient (Ensure you didn't allocate too much or too little space to a variable)
Data Types are consistent (I.e. You're using integer data types for integers if it's in the design)
There weren't errors caused special characters (You shouldn't have this problem if you used a proper delimiter)
My assumption is "get estimate rows" is he simply wants the number of rows returned. I'll leave that up to you to figure out how to determine that.
If the CSV file was created correctly, I wouldn't sweat it too much. Don't be afraid to ask for help or advice from your colleagues, that's how you learn!
Best of luck!

How do you think while formulating Sql Queries. Is it an experience or a concept?

I have been working on sql server and front end coding and have usually faced problem formulating queries.
I do understand most of the concepts of sql that are needed in formulating queries but whenever some new functionality comes into the picture that can be dont using sql query, i do usually fails resolving them.
I am very comfortable with select queries using joins and all such things but when it comes to DML operation i usually fails
For every query that i never done before I usually finds uncomfortable with that while creating them. Whenever I goes for an interview I usually faces this problem.
Is it their some concept behind approaching on formulating sql queries.
Eg.
I need to create an sql query such that
A table contain single column having duplicate record. I need to remove duplicate records.
I know i can find the solution to this query very easily on Googling, but I want to know how everyone comes to the desired result.
Is it something like Practice Makes Man Perfect i.e. once you did it, next time you will be able to formulate or their is some logic or concept behind.
I could have get my answer of solving above problem simply by posting it on stackoverflow and i would have been with an answer within 5 to 10 minutes but I want to know the reason. How do you work on any new kind of query. Is it a major contribution of experience or some an implementation of concepts.
Whenever I learns some new thing in coding section I tries to utilize it wherever I can use it. But here scenario seems to be changed because might be i am lagging in some concepts.
EDIT
How could I test my knowledge and
concepts in Sql and related sql
queries ?
Typically, the first time you need to open a child proof bottle of pills, you have a hard time, but after that you are prepared for what it might/will entail.
So it is with programming (me thinks).
You find problems, research best practices, and beat your head against a couple of rocks, but in the process you will come to have a handy set of tools.
Also, reading what others tried/did, is a good way to avoid major obsticles.
All in all, with a lot of practice/coding, you will see patterns quicker, and learn to notice where to make use of what tool.
I have a somewhat methodical method of constructing queries in general, and it is something I use elsewhere with any problem solving I need to do.
The first step is ALWAYS listing out any bits of information I have in a request. Information is essentially anything that tells me something about something.
A table contain single column having
duplicate record. I need to remove
duplicate
I have a table (I'll call it table1)
I have a
column on table table1 (I'll call it col1)
I have
duplicates in col1 on table table1
I need to remove
duplicates.
The next step of my query construction is identifying the action I'll take from the information I have.
I'll look for certain keywords (e.g. remove, create, edit, show, etc...) along with the standard insert, update, delete to determine the action.
In the example this would be DELETE because of remove.
The next step is isolation.
Asnwer the question "the action determined above should only be valid for ______..?" This part is almost always the most difficult part of constructing any query because it's usually abstract.
In the above example you're listing "duplicate records" as a piece of information, but that's really an abstract concept of something (anything where a specific value is not unique in usage).
Isolation is also where I test my action using a SELECT statement.
Every new query I run gets thrown through a select first!
The next step is execution, or essentially the "how do I get this done" part of a request.
A lot of times you'll figure the how out during the isolation step, but in some instances (yours included) how you isolate something, and how you fix it is not the same thing.
Showing duplicated values is different than removing a specific duplicate.
The last step is implementation. This is just where I take everything and make the query...
Summing it all up... for me to construct a query I'll pick out all information that I have in the request. Using the information I'll figure out what I need to do (the action), and what I need to do it on (isolation). Once I know what I need to do with what I figure out the execution.
Every single time I'm starting a new "query" I'll run it through these general steps to get an idea for what I'm going to do at an abstract level.
For specific implementations of an actual request you'll have to have some knowledge (or access to google) to go further than this.
Kris
I think in the same way I cook dinner. I have some ingredients (tables, columns etc.), some cooking methods (SELECT, UPDATE, INSERT, GROUP BY etc.) then I put them together in the way I know how.
Sometimes I will do something weird and find it tastes horrible, or that it is amazing.
Occasionally I will pick up new recipes from the internet or friends, then use parts of these in my own.
I also save my recipes in handy repositories, broken down into reusable chunks.
On the "Delete a duplicate" example, I'd come to the result by googling it. This scenario is so rare if the DB is designed properly that I wouldn't bother keeping this information in my head. Why bother, when there is a good resource is available for me to look it up when I need it?
For other queries, it really is practice makes perfect.
Over time, you get to remember frequently used patterns just because they ARE frequently used. Rare cases should be kept in a reference material. I've simply got too much other stuff to remember.
Find a good documentation to your software. I am using Mysql a lot and Mysql has excellent documentation site with decent search function so you get many answers just by reading docs. If you do NOT get your answer at least you are learning something.
Than I set up an example database (or use the one I am working on) and gradually build my SQL. I tend to separate the problem into small pieces and solve it step by step - this is very successful if you are building queries including many JOINS - it is best to start with some particular case and "polute" your SQL with many conditions like WHEN id = "123" which you are taking out as you are working towards your solution.
The best and fastest way to learn good SQL is to work with someone else, preferably someone who knows more than you, but it is not necessarry condition. It can be replaced by studying mature code written by others.
Your example is a test of how well you understand the DISTINCT keyword and the GROUP BY clause, which are SQL's ways of dealing with duplicate data.
Examples and experience. You look at other peoples examples and you create your own code and once it groks, you don't need to think about it again.
I would have a look at the Mere Mortals book - I think it's the one by Hernandez. I remember that when I first started seriously with SQL Server 6.5, moving from manual ISAM databases and Access database systems using VB4, that it was difficult to understand the syntax, the joins and the declarative style. And the SQL queries, while powerful, were very intimidating to understand - because typically, I was looking at generated code in Microsoft Access.
However, once I had developed a relatively systematic approach to building queries in a consistent and straightforward fashion, my skills and confidence quickly moved forward.
From seeing your responses you have two options.
Have a copy of the specification for whatever your working on (SQL spec and the documentation for the SQL implementation (SQLite, SQL Server etc..)
Use Google, SO, Books, etc.. as a resource to find answers.
You can't formulate an answer to a problem without doing one of the above. The first option is to become well versed into the capabilities of whatever you are working on.
The second option allows you to find answers that you may not even fully know how to ask. You example is fairly simplistic, so if you read the spec/implementation documentaion you would know the answer right away. But there are times, where even if you read the spec/documentation you don't know the answer. You only know that it IS possible, just not how to do it.
Remember that as far as jobs and supervisors go, being able to resolve a problem is important, but the faster you can do it the better which can often be done with option 2.