I am building a dynamic app.
The basic of the app is i can create a question. A question may have many columns. These columns will be displayed in table structure. Then the user will fill the details. Below is the sample.
Question:
1. List the projects available and their deadlines?
Columns:
1. Project - Textbox
2. Deadline - Textbox
So i will show this data in the table like below.
The user will fill the row and click on submit button. Another empty row will get added to add the another response like below.
The user will submit any no of responses.
Like this the no of columns will be dynamic and also the each column will have some validation like Unique,AcceptsNull etc...
How to create table structure in ms sql server to save the question,column and the responses.
Please help thanks in advance..
Your scenario is similar with the way in which Microsoft Project Server stores its data in MSSQL. In MSPE for each project, a task can have a dynamic number of columns. In your case, if you can make all your column types as VARCHAR, than your scenario simplifies even more.
The proposed structure would be like this:
This is the table with the questions:
tbl_Questions
+------------------------------------------------------------------+
| Id | Question |
+----------------------------------------------------------------- +
| RandomGUID1 | "List the projects available and their deadlines?" |
| RandomGUID2 | "List the projects available?" |
+------------------------------------------------------------------+
tbl_RelationTable
+---------------------------------------------------------------------------+
| Id | QuestionId | Column1 | Column2 | ... |Column 1000 |
+---------------------------------------------------------------------------+
| 1 | RandomGUID1 | RandomGUID111 | RandomGUID112 | | null |
| 2 | RandomGUID2 | RandomGUID113 | null | | null |
+---------------------------------------------------------------------------+
In this table you store all relations between tbl_Questions and the other tables. You define in this table a sufficient number of columns, here I proposed 1000, but maybe in your case 10-15 columns would be enough. One important aspect is that you need to use GUIDs for Question ID in order to be unique.
Now we define the real data tables.
This is the table where you define your answer columns:
tbl_AnswerColumns
+-----------------------------------------------+
|Id| RelationTableId | QuestionId | ColumnName |
+-----------------------------------------------+
| 1| RandomGUID111 | RandomGUID1 | Title |
| 2| RandomGUID112 | RandomGUID1 | Answer |
| 3| RandomGUID113 | RandomGUID2 | Title |
+-----------------------------------------------+
This is the table where you store the answers values:
tbl_AnswerValues
+-----------------------------------------------+
|Id| RelationTableId | QuestionId | Answer |
+-----------------------------------------------+
| 1| RandomGUID111 | RandomGUID1 | "Answer1" |
| 2| RandomGUID112 | RandomGUID1 | "Answer2" |
| 3| RandomGUID113 | RandomGUID2 | "Answer3" |
+-----------------------------------------------+
You need to define foreign keys in all tables in order to make the data retrieval much faster. This is why each table should contain a foreign key to the QuestionId.
By the information you've given I'm thinking something like this?
Questions
+---------------------------------------------------------+
| Id | Question |
+----+--------------------------------------------------- +
| 1 | "List the projects available and their deadlines?" |
+---------------------------------------------------------+
Answers
+-----------------------------------------------------------------------------------+
| Id | QuestionId | Order | Title | Anwser | Unique | Nullable | Values |
+----+------------+-------+------------+-------------+--------+----------+----------+
| 1 | 1 | 0 | "Project" | "Project 1" | True | False | "P1, P2" |
| 2 | 1 | 1 | "Deadline" | "Apr-15" | False | True | NULL |
+-----------------------------------------------------------------------------------+
Edit: I've added the validations. If you want the same validations for all anwers for the same question, you can also move the validation columns to the Questions-table.
Related
I have a spreadsheet which has two rows with three columns,
--------------------------------------
| title | id | roles
------------------------------------------
| DOC | 1 | pediatrician
-----------------------------------------
| NURSE | 2 | A&E
| | | pediatrics
| | | orthopedic
-----------------------------------------
| DOC | 3 | orthopedic
-----------------------------------------
In which row 2 (NURSE ) column 3 (roles) have a merged cell
using C# (openxml) I want to read column (roles) as one single values
can some one help?
I have a table with a bunch of data this is a small sample:
Header - Object name
Waarde
ExportRoot.a80_02_00_01_Status.Settings.Off
0
ExportRoot.a80_02_00_01_Status.Standby
0
ExportRoot.a80_02_00_01_Status.Cooling
1
ExportRoot.a80_02_00_01_Status.Drying
0
ExportRoot.a80_02_00_01_Status.Heating
0
ExportRoot.a80_02_00_01_Status.PrepDrain
0
I wish to style this table in a way to where its more readable by removing the object parts and indenting the table like how it looks below.
| Header - Object name | Waarde |
|--------------------------|---------|
| ExportRoot | |
| | a80_02_00_01_Status | |
| | | Settings | |
| | | | Off | 0 |
| | | | Standby | 0 |
| | | | Cooling | 1 |
| | | | Drying | 0 |
| | | | Heating | 0 |
| | | | PrepDrain | 0 |
Is there a way of doing this and if so what should I be looking for all I've found so far are tables with sub tables and that not exactly what I'm looking for. If anyone has an idea let me know I'm super lost.
So basically you need a TreeListView:
There is one project on CodeProject that you can check:
WPF TreeListView Control
There is also commercial products, like DevExpress:
DevExpress TreeList View
Attendance Table
id | rollno | faculty | date | PresentAbsent
---|---------|---------|------------|--------------
1 | RP1201 | ABC | 12/12/2016 | P
2 | RP1202 | ABC | 12/12/2016 | A
Leave Table
Lid | rollno | startdate | enddate | full-half-day | time
----|--------|------------|------------|---------------|---------------
1 | RP1201 | 11/12/2016 | 12/12/2016 | fullday | Not applicable
2 | RP1202 | 12/12/2016 | 12/12/2016 | halfday | 10.30-11.30
Required Report
rollno | totallecture | totalpresent | totalabsent | totalleave | withoutLeave% | withLeave%
-------|--------------|--------------|-------------|------------|---------------|-----------
RP1201 | 12 | 6 | 6 | 2 | 50% | 66.66%
From above table logic at the starting it works fine but table entry increase it takes more time to calculate report.
Please help me to change table logic which help me to execute report
in few second
Please any other suggestion would be appreciated
In your Leave table, use a trigger. Whenever there is a new Leave inserted, this trigger will update the Attendance table for PresentAbsent=Awith FD or HD.
Now while creating report, consider these FD and HD to calculate the TotalAbsent and TotalLeave.
If you are able to figure out the report query, this addition will do some modification on it. Hope I am clear. Let me know in comments if you have any question.
Do something like this.
Create Leave table, with total number of days for leave. For half day, it can be 0.5 which uses roll number are foreign key.
Something like this
Lid | rollno | startdate | enddate | full-half-day | time |numberofdays
----|--------|------------|------------|---------------|---------------|------------
1 | RP1201 | 11/12/2016 | 12/12/2016 | fullday | Not applicable|2
2 | RP1202 | 12/12/2016 | 12/12/2016 | halfday | 10.30-11.30 |0.5
After that query it like this (I'm writing a pseudo code).
select sum(days-of-leave) from LeaveTable where rollnumber=rp1001
for total absent and present do this.
select count(presentabsent) as absent from attendence
where rollnumber=rp1001 and presentabsent=A
I have a problem with displaying and editing some data from database to ASP.Net webpage.
Data from database consist from few different tables:
Table Files, witch contains file_id and a file name
| file_id | file_name |
--------------------------
| GUID | VARCHAR |
file is saved in database as a collection of lines for one file_id,
Table Items,witch contains basically all the lines from all the files
| item_id | file_id | step | number |
---------------------------------------------------
| GUID | VARCHAR | BIGINT | BIGINT |
Table Wording, witch contains all distinctive wording
| wording_id | wording_eng | description |
-----------------------------------------
| GUID | VARCHAR | VARCHAR |
And M_N_table witch contains connection between items and wording
| item_id | wording_id |
----------------------------
| GUID | GUID |
my final display table should look like this and should be editable
| | file1 | file2 | file3 |.........| fileN | | |
| sortorder --------------------------------------------------------------------------| wording_eng | desription |
| | step | number | step | number | step | number |.........| step | number | | |
------------------------------------------------------------------------------------------------------------------
| 1 | 10 | 15 | | | | |.........| | | something1 | something2 |
------------------------------------------------------------------------------------------------------------------
| 2 | | | | | 25 | 15 |.........| 5 | 17 | something3 | something4 |
------------------------------------------------------------------------------------------------------------------
| 3 | 2 | 4 | 5 | 16 | 17 | 3 |.........| 1 | 15 | something5 | something6 |
So for every file from some selected list,witch means variable number of files, I need to read all the wordings and if a wording is connected to item in M_N_table and that item exist in selected files I have to write value of step and number to that files column as shown, if they don't exist it will be written blank value.
Problem I'm having is creating Table or DataList or GridView where I can have connection to item_id and wording_id when I'm editing data. I managed to create "pivot" datatable in C# in backcode, using all of these tables and created gridview with dynamic number of columns but problem is I don't have information about what item_id I'm actually editing it just goes back to changing value in datatable.
What is the best way to display this data? I tried making dynamic pivot table in SQL to display it directly with gridview but without aggregation it's impossible,so I had to do it with datatable's in C# back-code. And how can I make it so that when I edit data in displayed table I get the same changes in database?
I have two separate databases that have data that coincides with another. However they are not relational.
I'm trying pro-grammatically create a relationship to build some statistics in C#. I'm looking for the number of actions in a case and its assets associated.
From one database I can see what asset belongs to what case:
| 7AU45448 | cases/unchanged/
| 7AI61361 | cases/unchanged/
| 8C52A5A1 | cases/unchanged/
| 8643Y053 | cases/unchanged/
| 8643Y052 | cases/unchanged/
| 8643Y051 | cases/unchanged/
| 8643Y050 | cases/unchanged/
| B4F043RB | cases/ups01/
| B4F043R7 | cases/ups01/
| B4F043R5 | cases/ups01/
| B4F043QZ | cases/ups01/
| B4F043QY | cases/ups01/
| B4F043RA | cases/ups01/
| B4F043R1 | cases/ups01/
| B4F043R8 | cases/ups01/
| B4F043R9 | cases/ups01/
| B4F043QX | cases/ups01/
| B4F043R3 | cases/ups01/
| B4F043QW | cases/ups01/
| B4F043R4 | cases/ups01/
| B4F043RC | cases/ups01/
| B4F043R2 | cases/ups01/
| B4F043R0 | cases/ups01/
| B4F043RD | cases/ups01/
| B4F043R6 | cases/ups01/
The other database is for logs, and holds no information on the case itself. Only the asset and detail are inside.
The information in this database is like:
7AU45448 | Processed file
7AU45448 | Download file
7AU45448 | View file
I can easily do a action count per asset on the database but not on the case. This is why I need the relationship.
If anyone has and Ideas or suggestions please let me know!
Thanks in Advance!
Since your definition of "not relational" was merely meant to be "without constraints", you should be able to compare data in two different databases as long as the field you're joining on is the same data type. Just make sure your left table is the table with the values you care about if you use a LEFT OUTER JOIN. In this case, [db1].[dbo].[table1] is the left table.
Example:
SELECT [db1].[dbo].[table1].*, [db2].[dbo].[table2].*
FROM [db1].[dbo].[table1]
LEFT OUTER JOIN [db2].[dbo].[table2] ON [db1].[dbo].[table1].[field_in_db1_table1] = [db2].[dbo].[table2].[field_in_db2_table2]