Click here to Skip to main content
15,887,175 members
Home / Discussions / Database
   

Database

 
AnswerRe: prior action plan to prevent sql database corruption Pin
Richard Andrew x642-Sep-23 2:38
professionalRichard Andrew x642-Sep-23 2:38 
GeneralRe: prior action plan to prevent sql database corruption Pin
Dave Kreskowiak2-Sep-23 3:33
mveDave Kreskowiak2-Sep-23 3:33 
AnswerRe: prior action plan to prevent sql database corruption Pin
jschell4-Sep-23 5:42
jschell4-Sep-23 5:42 
GeneralRe: prior action plan to prevent sql database corruption Pin
Kar_Malay2-Oct-23 9:22
Kar_Malay2-Oct-23 9:22 
QuestionFetch row and display in frontend column Pin
Kesiena26-Aug-23 3:14
Kesiena26-Aug-23 3:14 
AnswerRe: Fetch row and display in frontend column Pin
David Mujica28-Aug-23 3:16
David Mujica28-Aug-23 3:16 
AnswerRe: Fetch row and display in frontend column Pin
jschell29-Aug-23 5:01
jschell29-Aug-23 5:01 
AnswerRe: Fetch row and display in frontend column Pin
Rohan Saadat17-Nov-23 5:10
Rohan Saadat17-Nov-23 5:10 
It sounds like you have a scenario where you want to save data across multiple tables in a database using a single form. Additionally, you want to create a master table to store foreign keys and display the data in the frontend. Let's break down your requirements:

1. Generating a Common ID for Multiple Tables:
When you want to add data to multiple tables at once and have them share a common identifier, you typically use a primary key (ID) that is common across all related tables. This can be achieved through database design and relationships.

For example, let's say you have four tables: TableA, TableB, TableC, and TableD. Each of these tables has its own data, but they all share a common identifier, which could be a foreign key linking to a MasterTable.

Here's a simplified example:
CREATE TABLE MasterTable (
MasterID INT PRIMARY KEY,
-- Other columns as needed
);

CREATE TABLE TableA (
ID INT PRIMARY KEY,
MasterID INT,
-- Other columns for TableA
FOREIGN KEY (MasterID) REFERENCES MasterTable(MasterID)
);

-- Repeat the same structure for TableB, TableC, and TableD
When you insert data into MasterTable, you generate a unique MasterID and use it as a foreign key in the other tables. This way, you can maintain relationships between the tables.

2. Displaying Table Rows as Columns in the Frontend:
If you want to display data from a table row as columns in the frontend, you'll need to use SQL queries or your backend programming language to transform the data before sending it to the frontend.

For example, suppose you have a table named Data:
CREATE TABLE Data (
ID INT PRIMARY KEY,
MasterID INT,
ColumnName VARCHAR(50),
ColumnValue VARCHAR(50),
FOREIGN KEY (MasterID) REFERENCES MasterTable(MasterID)
);

This table stores data in a key-value pair format, where each row represents a piece of data related to a MasterID. To display this data with columns dynamically created based on the ColumnName values, you can use a pivot query.

Here's a simplified example in SQL:
SELECT
MasterID,
MAX(CASE WHEN ColumnName = 'Column1' THEN ColumnValue END) AS Column1,
MAX(CASE WHEN ColumnName = 'Column2' THEN ColumnValue END) AS Column2,
-- Add more columns as needed
FROM Data
GROUP BY MasterID;

This query transforms rows into columns based on the unique values in the ColumnName column.

Keep in mind that the specifics of these solutions might depend on the exact requirements of your application, the database system you're using, and the programming language/framework of your frontend.
QuestionMulti-user use the database at the same time Pin
Siavash.BRY11-Aug-23 23:49
Siavash.BRY11-Aug-23 23:49 
AnswerRe: Multi-user use the database at the same time Pin
Richard Deeming13-Aug-23 21:18
mveRichard Deeming13-Aug-23 21:18 
AnswerRe: Multi-user use the database at the same time Pin
Dave Kreskowiak14-Aug-23 5:12
mveDave Kreskowiak14-Aug-23 5:12 
AnswerRe: Multi-user use the database at the same time Pin
jschell14-Aug-23 6:37
jschell14-Aug-23 6:37 
QuestionTough one Pin
Richard Andrew x6431-Jul-23 4:59
professionalRichard Andrew x6431-Jul-23 4:59 
AnswerRe: Tough one Pin
Richard Deeming31-Jul-23 5:33
mveRichard Deeming31-Jul-23 5:33 
GeneralRe: Tough one Pin
Richard Andrew x6431-Jul-23 5:35
professionalRichard Andrew x6431-Jul-23 5:35 
QuestionWhy do some websites provide Demo for their premium html themes while the codes can be seen using inspection tool in chrome? Pin
Alex Dunlop11-Jul-23 6:30
Alex Dunlop11-Jul-23 6:30 
AnswerRe: Why do some websites provide Demo for their premium html themes while the codes can be seen using inspection tool in chrome? Pin
PIEBALDconsult11-Jul-23 6:01
mvePIEBALDconsult11-Jul-23 6:01 
QuestionORDER BY in UNION Pin
_Flaviu29-May-23 5:14
_Flaviu29-May-23 5:14 
AnswerRe: ORDER BY in UNION Pin
jschell29-May-23 6:15
jschell29-May-23 6:15 
GeneralRe: ORDER BY in UNION Pin
_Flaviu29-May-23 7:54
_Flaviu29-May-23 7:54 
AnswerRe: ORDER BY in UNION Pin
Richard Deeming29-May-23 21:37
mveRichard Deeming29-May-23 21:37 
AnswerRe: ORDER BY in UNION Pin
Richard Andrew x6431-May-23 2:41
professionalRichard Andrew x6431-May-23 2:41 
GeneralRe: ORDER BY in UNION Pin
_Flaviu13-Jun-23 8:28
_Flaviu13-Jun-23 8:28 
AnswerRe: ORDER BY in UNION Pin
Richard Andrew x6413-Jun-23 13:19
professionalRichard Andrew x6413-Jun-23 13:19 
GeneralRe: ORDER BY in UNION Pin
_Flaviu14-Jun-23 9:29
_Flaviu14-Jun-23 9:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.