C#C
C#2y ago
48 replies
Mek

✅ Common Keys in Database Tables

cmd.CommandText = @"CREATE TABLE IF NOT EXISTS
                    [students] (
                    [Id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
                    [FirstName] VARCHAR(2048),
                    [MiddleName] VARCHAR(2048),
                    [LastName] VARCHAR(2048),
                    [AlternateFirstName] VARCHAR(2048),
                    [AlternateLastName] VARCHAR(2048),
                    [PhysicalAddress] VARCHAR(2048),
                    [City] VARCHAR(2048),
                    [State] VARCHAR(2048),
                    [Zip] INTEGER,
                    [County] VARCHAR(2048),
                    [Country] VARCHAR(2048),
                    [PrimaryNumber] VARCHAR(2048),
                    [SecondaryNumber] VARCHAR(2048),
                    [PrimaryEmail] VARCHAR(2048),
                    [SecondaryEmail] VARCHAR(2048),
                    [Birthday] VARCHAR(2048),
                    [ParentEmail] VARCHAR(2048),
                    [ParentHomePhone] VARCHAR(2048),
                    [ParentHomePhone2] VARCHAR(2048),
                    [ParentCellPhone] VARCHAR(2048),
                    [ParentCellPhone2] VARHCAR(2048),
                    [StudentAddress] VARCHAR(2048)
                    )";

cmd2.CommandText = @"CREATE TABLE IF NOT EXISTS
                    [staff] (
                    [Id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
                    [FirstName] VARCHAR(2048),
                    [MiddleName] VARCHAR(2048),
                    [LastName] VARCHAR(2048),
                    [AlternateFirstName] VARCHAR(2048),
                    [AlternateLastName] VARCHAR(2048),
                    [PhysicalAddress] VARCHAR(2048),
                    [City] VARCHAR(2048),
                    [State] VARCHAR(2048),
                    [Zip] INTEGER,
                    [County] VARCHAR(2048),
                    [Country] VARCHAR(2048),
                    [PrimaryNumber] VARCHAR(2048),
                    [SecondaryNumber] VARCHAR(2048),
                    [PrimaryEmail] VARCHAR(2048),
                    [SecondaryEmail] VARCHAR(2048),
                    [StudentName] VARCHAR(2048),
                    [NumberOfStudents] INTEGER,
                    )";

cmd3.CommandText = @"CREATE TABLE IF NOT EXISTS
                    [parents] (
                    [Id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
                    [FirstName] VARCHAR(2048),
                    [MiddleName] VARCHAR(2048),
                    [LastName] VARCHAR(2048),
                    [AlternateFirstName] VARCHAR(2048),
                    [AlternateLastName] VARCHAR(2048),
                    [PhysicalAddress] VARCHAR(2048),
                    [City] VARCHAR(2048),
                    [State] VARCHAR(2048),
                    [Zip] INTEGER,
                    [County] VARCHAR(2048),
                    [Country] VARCHAR(2048),
                    [PrimaryNumber] VARCHAR(2048),
                    [SecondaryNumber] VARCHAR(2048),
                    [PrimaryEmail] VARCHAR(2048),
                    [SecondaryEmail] VARCHAR(2048),
                    [StudentName] VARCHAR(2048)
                    )";
I'm writing my database logic for creating my relative database. I'm trying to find a good way to link these three tables together through a common variable. For example: The principle receives a new student and they get enrolled. The students information will go into the students table, the students parents information will go in the parents table, and the student will get assigned to a teacher, or number of teachers, and the teachers information already exists for when they were added to the gradebook on hire. So if a teacher needs to see parent/student information or the principle needs to see what teacher is assigned to the student, what's a good way to link these three tables together so that I can just do one database call and have access to the all the information from all 3 tables?
Was this page helpful?