IDSC 3103 Notes

.docx

School

University of Minnesota-Twin Cities *

*We aren’t endorsed by this school

Course

3103

Subject

Computer Science

Date

Apr 3, 2024

Type

docx

Pages

42

Uploaded by 7194101S

Report
IDSC 3103 Notes 1/22 StdNo CHAR(11) = ssn (include hyphens) CHAR= standardized # of characters Having fixed length does not require it to be that VARCHAR(50) = “variable” 50 letters allowed (good for name length) Types of columns: 1. Primary keys 2. Foreign keys 3. Non-key columns (ordinary data, name, age, etc) NOT NULL = something must be entered StdGPA DECIMAL(2,1), #3.8 First number is total # of digits, second # is how many after the decimal - Can have more, but not less -- Primary key #must be there, and unique (no two entities w/ same key) - usually auto-generated by system (ex. StdNo) CONSTRAINT Student Excel: -- CREATE TABLE statement, column naming, data types -- based on data source, required vs. optional values CREATE TABLE Student ( -- Data type based on data source StdNo CHAR(11), StdFirstName VARCHAR(50) NOT NULL, StdLastNameVARCHAR(50) NOT NULL, StdCity VARCHAR(50) NOT NULL, StdState CHAR(2) NOT NULL, StdZip CHAR(10) NOT NULL, StdMajor CHAR(4), StdClass CHAR(2), StdGPA DECIMAL(2,1), -- Primary key CONSTRAINT PKStudent PRIMARY KEY (StdNo) ) Errors
1. Syntax errors (ex. Forgot a comma) 2. Run Time error (ran but didn’t work out) 3. Logical Error (result doesn’t make sense, ex. Forgot the state column) Import Table to Database Steps 1. Make sure schema is bold 2. Refresh 3. Click on table and choose “data table import wizard” 4. Find it in IDSC 3103 Folder Course: CREATE TABLE Course ( CourseNo CHAR(6), CrsDesc VARCHAR(250) NOT NULL, CrsUnits INTEGER, -- Numerical data types CONSTRAINT PKCourse PRIMARY KEY (CourseNo), -- Unique key CONSTRAINT UKCrsDesc UNIQUE KEY (CrsDesc) ) - Phone number and email is not good for primary key Faculty: Remember: - Column design (ex. Having enough char for phone #) - Date: yyyy-mm-dd (not char or number) 0 records found (look for dates and NULLS) 1. Create table 2. Drop table (can’t always do) 3. Alter table Ex. ALTER TABLE Faculty MODIFY COLUMN FacZipCode CHAR(10)
1/24 - Foreign Keys Course is parent table Offering is child table Foreign key How To: CONSTRAINT PKOffering PRIMARY KEY (OfferNo), -- Foreign keys CONSTRAINT FKCourse FOREIGN KEY (CourseNo) REFERENCES Course (CourseNo) CONSTRAINT FKFaculty FOREIGN KEY (FacNo) REFERENCES Faculty (FacNo) ) Offering Notepad ++ CREATE TABLE Offering ( -- Data type based on data source OfferNo INTEGER, CourseNo CHAR(6) NOT NULL, --can't be blank, require course # OffTerm VARCHAR(6) NOT NULL,
-- Data type based on data source OffYear INTEGER NOT NULL, OffLocation CHAR(6), OffTime TIME, -- Date/Time data type OffDays CHAR(4), FacNo CHAR(11), --don't need "not null", maybe no prof CONSTRAINT PKOffering PRIMARY KEY (OfferNo), -- Foreign keys CONSTRAINT FKCourse FOREIGN KEY (CourseNo) REFERENCES Course (CourseNo), CONSTRAINT FKFaculty FOREIGN KEY (FacNo) REFERENCES Faculty (FacNo) ) Will create sections of the course table (offering = sections) - Make sure all CourseNo are filled in (not blank)
1/29 Compound primary key (in enrollment) -- Compound primary key CONSTRAINT PKEnrollment PRIMARY KEY (OfferNo, StdNo), *Each key is also a foreign key and OfferNo and StdNo must exist Logical input of sections CONSTRAINT FKOffering FOREIGN KEY (OfferNo) REFERENCES Offering (OfferNo) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT FKStudent FOREIGN KEY (StdNo) REFERENCES Student (StdNo) -- Self-referencing key, skip and come back to at the end (from Faculty
Ex. ON DELETE RESTRICT action ensures that you cannot delete an author who has books associated with them in the Books table, preserving the link between a book and its author. Ex. ON DELETE CASCADE action indicates that if a publisher is deleted, all associated magazines in the Magazines table will also be removed. Assignment: We have to import employees last Can’t use the same FK Name University: ex. Nikki is Julia’s supervisor (faculty table) ALTER TABLE ADD CONSTRAINT FKSupervisor FOREIGN KEY (FacSupervisor)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help