SQL table help needed

  • frih
  • Novice
  • Novice
  • User avatar
  • Posts: 19

Post 3+ Months Ago

Here is a table--
Quote:

$movie = “CREATE TABLE movie (
movie_id int(11) NOT NULL auto_increment,
movie_name varchar(255) NOT NULL,
movie_type tinyint(2) NOT NULL default 0,
movie_year int(4) NOT NULL default 0,
movie_leadactor int(11) NOT NULL default 0,
movie_director int(11) NOT NULL default 0,
PRIMARY KEY (movie_id),
KEY movie_type (movie_type,movie_year)
)”;



I am unable to understand the purpose of last line-- "KEY movie_type(movie_type,movie_year)"

Why we have used KEY word. Is it creating primary key or so??

Need help--- I am new to mysql
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • dark_lord
  • Graduate
  • Graduate
  • User avatar
  • Posts: 162
  • Loc: India-Kolkata

Post 3+ Months Ago

I don't know if I can explain right. Trying...

in your query, you used KEY movie_type(movie_type,movie_year) but it is not defined as unique or Primary!

so it is not creating any of the above key since it is not defined!

note that mysql allows the word key as a synonym for index

and i have little idea about it's use!
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

dark_lord wrote:
note that mysql allows the word key as a synonym for index


I never knew that.
I've been under the impression there was "PRIMARY KEY", "FOREIGN KEY", "UNIQUE", and "INDEX", with "KEY" requiring a keyword before it. :scratchhead:
  • dark_lord
  • Graduate
  • Graduate
  • User avatar
  • Posts: 162
  • Loc: India-Kolkata

Post 3+ Months Ago

joebert wrote:
dark_lord wrote:
note that mysql allows the word key as a synonym for index


I never knew that.


You can go to this page

http://dev.mysql.com/doc/refman/5.0/en/ ... table.html

and search for

KEY is normally a synonym for INDEX

I hope u missed this documentation and stop scratching your head :D

Additional Info :

KEY is normally a synonym for INDEX. The key attribute PRIMARY KEY can also be specified as just KEY when given in a column definition. This was implemented for compatibility with other database systems.

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 105 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.