Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8421391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:08:17+00:00 2026-06-10T03:08:17+00:00

I have a query on database table structure. My Patient Details table in a

  • 0

I have a query on database table structure.
My Patient Details table in a SQL Server 2008 database looks like this:

–PatientId(PK)– –PatientType– –DoctorId(FK)– –DateOfVisit– –PrescriptionId(FK)–

Each patient may visit the hospital multiple times. I need to link all the visits of a patient and show them in a linked way that the admin can navigate with the previous and next visits..

So I think I can do it only by having a record for each visit with a VisitId.

I need to be Careful that the database should not be loaded with unnecessary fields. Also it should not affect the fetching time badly.

I think these are the available ways. Suggest me if any available.

–PatientId(PK)– –PatientType– –DoctorId(FK)– –DateOfVisit– –PrescriptionId(FK)– –VisitId– –PrevVisitId– NextVisitId–

or

having a separate table for Visit as

–VisitId(PK)– -PrevVisitId(FK)– –NextVisitId(FK)–

Apologies if my post is duplicate.. Correct me, redirect me wherever/whenever needed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T03:08:19+00:00Added an answer on June 10, 2026 at 3:08 am

    So I think I can do it only by having a record for each visit with a
    VisitId.

    You need a row for each visit. You need a key for each row. The key doesn’t need to be a single id number. I think the very least you need to record for each visit is

    create table visits (
      patient_id integer not null, -- references patients (patient_id), not shown
      doctor_id integer not null,  -- references doctors (doctor_id), not shown
      office_visit_start timestamp not null default current_timestamp,
      primary key (patient_id, office_visit_start)
    );
    
    insert into visits values (1, 1, '2012-02-01 08:00');
    insert into visits values (1, 1, '2012-02-01 15:00');
    insert into visits values (1, 1, '2012-03-01 09:33');
    insert into visits values (2, 1, '2012-02-01 09:00');
    

    (Exact syntax varies depending on your dbms platform.) You can find the previous and next visits by fairly simple queries–“office_visit_start” will give you the order of a patient’s visits.

    Example queries . . .

    -- Previous visit for patient # 1 (before 2012-02-01 15:00)
    select patient_id, max(office_visit_start)
    from visits 
    where patient_id = 1
      and office_visit_start < '2012-02-01 15:00'
    group by patient_id
    
    -- Next visit for patient # 1 (after 2012-02-01 15:00)
    select patient_id, min(office_visit_start)
    from visits 
    where patient_id = 1
      and office_visit_start > '2012-02-01 15:00'
    group by patient_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created my database by this sql query: (CREATE DATABASE + DBName +
I have a MySQL database table with this structure: table id INT NOT NULL
I have a table in SQL Server 2000 that I am trying to query
I have the following 2 tables defined in a SQL Server database: CREATE TABLE
I have a database containing a single huge table. At the moment a query
Given SQL as an input, I have to query a PostgreSQL database and return
In my SQL database I have a query that turns values in multiple rows
I have a database/table in SQLITE using the following structure CREATE TABLE milestones (
I have created this query to fetch some result from database. Here is my
I have a database table structure as follow: datatype data mytable now datatype has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.