muhammedahmetsekerci / CS50-SQL

CS50's Introduction to Databases with SQL - 2024 Course
6 stars 1 forks source link

Week 6 (Scaling)/ Happy To Connect #1

Open v4run3 opened 4 weeks ago

v4run3 commented 4 weeks ago

CREATE DATABASE linkedin; USE linkedin;

CREATE TABLE Users( id INT AUTO_INCREMENT, first_lastname VARCHAR(30) NOT NULL, username VARCHAR(25) NOT NULL, password VARCHAR(128) NOT NULL, PRIMARY KEY(id) );

CREATE TABLE Schools ( id INT AUTO_INCREMENT, school_name VARCHAR(50) NOT NULL, school_type ENUM('Primary', 'Secondary', 'Higher Education') NOT NULL, school_location VARCHAR(32) NOT NULL, school_year DATE NOT NULL, PRIMARY KEY(id) );

CREATE TABLE Companies( id INT AUTO_INCREMENT, company_name VARCHAR(30) NOT NULL, company_industry VARCHAR(20) NOT NULL, company_locationVARCHAR(20) NOT NULL, PRIMARY KEY(id) );

CREATE TABLE people_connections( id INT AUTO_INCREMENT, user_id INT NOT NULL, following_user_id INT NOT NULL, connection_date DATE NOT NULL, PRIMARY KEY(id), FOREIGN KEY(user_id) REFERENCES Users(id), FOREIGN KEY(following_user_id) REFERENCES Users(id) );

CREATE TABLE school_connections( id INT AUTO_INCREMENT, user_id INT NOT NULL, school_id INT NOT NULL, start_date DATE NOT NULL, end_date DATE NOT NULL, degree_type VARCHAR(10) NOT NULL, PRIMARY KEY(id), FOREIGN KEY(user_id) REFERENCES Users(id), FOREIGN KEY(school_id) REFERENCES Schools(id) );

CREATE TABLE company_connections( id INT AUTO_INCREMENT, user_id INT NOT NULL, company_id INT NOT NULL, start_date DATE NOT NULL, end_date DATE NOT NULL, PRIMARY KEY(id), FOREIGN KEY(user_id) REFERENCES Users(id), FOREIGN KEY(company_id) REFERENCES Companies(id) );

muhammedahmetsekerci commented 3 weeks ago

There is no problem in both spellings.

v4run3 commented 3 weeks ago

In the school_type u have used: school_type ENUM(Primary, Secondary, Higher Education) NOT NULL, (which will give you error since you are using `` inside the ENUM) instead you should be using '' to pass the data inside the ENUM.

muhammedahmetsekerci commented 3 weeks ago

Hello again, I tried both codes and the tables were created without any problems, although there were 1-2 errors due to SQLite3. Not only does the school desk you mentioned not appear, but it also doesn't appear when I try your code. This is probably a bug caused by the enum code and sqlite3. Also, when I try the code you sent with .read, both the Companies table and the school table do not appear in the schema and tables sections.