SvekkeHomie Posted November 8, 2013 Share Posted November 8, 2013 I just started with SQL and thus following the online W3Schools course. Unfortunately now stuck with adding a constraint to an already created table... http://www.w3schools.com/sql/sql_unique.asp After creating a table with... CREATE TABLE MyTest(MyVar1 int,MyVar2 varchar(255)) and trying to put a unique constraint on the MyVar1 column with... ALTER TABLE MyTestADD UNIQUE (MyVar1) I get "Error 1: could not prepare statement (1 near "UNIQUE"; syntax error)". Anyone ? Link to comment Share on other sites More sharing options...
justsomeguy Posted November 8, 2013 Share Posted November 8, 2013 Which database system and version are you using? Link to comment Share on other sites More sharing options...
SvekkeHomie Posted November 9, 2013 Author Share Posted November 9, 2013 The one provided by the W3Schools site, SQL Tryit Editor v1.2.No idea what db system is behind this ? Link to comment Share on other sites More sharing options...
SvekkeHomie Posted November 10, 2013 Author Share Posted November 10, 2013 My problems with adding constraints using the Tryit editor continue ... Adding a table with... CREATE TABLE PersonTest(PersonID int PRIMARY KEY,Name varchar(255)) no problem, but then subsequently adding another table... CREATE TABLE OrderTest(OrderID int PRIMARY KEY,OrderDesc varchar(255),PersonID int FOREIGN KEY REFERENCES PersonTest(PersonID)) Gives me a similar "Error 1: could not prepare statement (1 near "FOREIGN"; syntax error)". The course content becomes hard to test this way Link to comment Share on other sites More sharing options...
justsomeguy Posted November 11, 2013 Share Posted November 11, 2013 Yeah, that's difficult to test. If I click on the question mark icon near the database then it looks like it is using the browser's WebSQL API to create the database, so it's actually going to be dependent on what your browser supports. It sounds like WebSQL is based on an older version of SQLite that doesn't support foreign keys, so that's probably the issue. You might want to download and install MySQL in order to get a full-featured database to test with. Access might be another option if you already own it. You can probably find a free web host that will give you a hosting account with MySQL where you could test also. Link to comment Share on other sites More sharing options...
SvekkeHomie Posted November 12, 2013 Author Share Posted November 12, 2013 That indeed probably explains my issues and why they don't put a "Try it yourself" button after these code snippets ! Uh ... W3Schools ... maybe a good idea to mention that not all code in the course can be tested with the built-in Tryit Editor ? Losing valuable time this way Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now