Last post Aug 01, 2012 07:37 PM by rsiqueira
Jun 03, 2010 01:09 AM|SLORider|LINK
This should be a simple question...
I am porting a MySQL application to MS-SQL. The following MySQL code creates a table with indexes (emphasis on the last four lines):
CREATE TABLE user (id integer not null primary key auto_increment,
email varchar(255) not null,
index idx_uniqid (uniqid),
index emailidx (email),
index enteredindex (entered) )
I have converted the code to:
CREATE TABLE user (id integer not null primary key IDENTITY(1,1),
email varchar(255) not null UNIQUE,
foreignkey varchar(100) );
CREATE INDEX idx_uniqid ON user (uniqid);
CREATE INDEX emailidx ON user (email);
CREATE INDEX enteredindex ON user (entered)
However, I'm stuck on this line of the MySQL code:
Each of the other three "index" statements include an index name and are in the form:
index name (column)
However, "index (foreignkey)" appears to be missing a name. Does this create an "anonymous" index on the
foreignkey column? Or, is it doing something else?
What is the proper conversion for "index (foreignkey)"?
I'm not familiar with MySQL, thus it's awful difficult to port the code when you don't know what the original code does! LOL!
Thanks for any help.
Aug 01, 2012 07:37 PM|rsiqueira|LINK
The index is not anonymous or unnamed.
If you don't specify the name in your "create table", then the index will have the same name of the field.
So you need to do this query to create the index (you can have an index name with the same name of the original field to be indexed):
CREATE INDEX foreignkey ON user (foreignkey);
You can also view all your index names using this query:
SHOW INDEX FROM user;