C
C#4w ago
yummy_bee

SQL code

"Add a Quality Label table with a foreign key from the Suppliers, with the default value corresponding to 'medium' quality. Don't forget to add a column to the Suppliers for the foreign key. Also add the following values to the table" we are using the northwind schema and i have tried to insert this but i keep getting invalid column name no matter what i change it to and i dont know why.
No description
22 Replies
FusedQyou
FusedQyou4w ago
Put the first two lines on a single line maybe The error is wrong I assume it does this because the SQL before it is wrong Otherwise idk, I let EntityFramework do my SQL rather than doing it manually
yummy_bee
yummy_bee4w ago
do you mean like this?
No description
FusedQyou
FusedQyou4w ago
Yes, guess that aint it I tried replicating the SQL and it was valid for me
yummy_bee
yummy_bee4w ago
Hmm yeah okay weird
FusedQyou
FusedQyou4w ago
Can you copy paste the code in here?
yummy_bee
yummy_bee4w ago
ALTER TABLE Suppliers ADD QualityID int; CREATE TABLE Quality (QualityID int PRIMARY KEY, QualityLevel varchar(20) NOT NULL); INSERT INTO Quality (QualityID, QualityLevel) VALUES (0, 'Acceptable'), (1, 'Medium'), (2, 'High'); UPDATE Suppliers SET QualityID = 1;
FusedQyou
FusedQyou4w ago
Sorry. No idea. This looks valid to me
yummy_bee
yummy_bee4w ago
when i hold the mouse over Quality it says there already is an object named Quality in the databse which is weird because there should not be
FusedQyou
FusedQyou4w ago
I'm sure somebody else would know
yummy_bee
yummy_bee4w ago
yeah okay thank you
FusedQyou
FusedQyou4w ago
Oh, then change your syntax to CREATE TABLE IF NOT EXISTS maybe This would only make a table with the given name if it doesn't exist yet, otherwise it would throw an error
yummy_bee
yummy_bee4w ago
yeah i get more errors so it might be somthing else that is wrong
Angius
Angius4w ago
Try quoting the table names
yummy_bee
yummy_bee4w ago
like this?
No description
Angius
Angius4w ago
Table names
yummy_bee
yummy_bee3w ago
I tried that and I still get the same error unfortunately
Angius
Angius3w ago
What SQL dialect is that?
yummy_bee
yummy_bee3w ago
I am not sure I think standard sql We work in microsoft SQL server
Angius
Angius3w ago
T-SQL then Huh, should just work
yummy_bee
yummy_bee3w ago
Yeah I know it’s weird
Angius
Angius3w ago
It works just fine in OneCompiler ¯\_(ツ)_/¯ https://onecompiler.com/sqlserver/42tepjjsf Though I do use " instead of ' for strings here
yummy_bee
yummy_bee3w ago
Yeah, if it works in the compiler it should be fine maybe it’s just a problem on my computer
Want results from more Discord servers?
Add your server