lipun4u Posted October 22, 2009 Share Posted October 22, 2009 I have arequirement that a table has to contain 3 columns, user_id, url and name. I want to make the url primary key. Go throw the following sql query. mysql> CREATE TABLE blog_details ( -> user_id INT(11), -> blogname VARCHAR(1024), -> blogurl VARCHAR(1024) NOT NULL, -> PRIMARY KEY(blogurl), -> FOREIGN KEY (user_id) REFERENCES login(user_id) -> ON DELETE CASCADE -> ); ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes How can I fix the above error ??? Quote Link to comment https://forums.phpfreaks.com/topic/178576-sql-key-error/ Share on other sites More sharing options...
Mchl Posted October 22, 2009 Share Posted October 22, 2009 Why do you think making url a primary key is a good idea at all? Quote Link to comment https://forums.phpfreaks.com/topic/178576-sql-key-error/#findComment-941767 Share on other sites More sharing options...
Daniel0 Posted October 22, 2009 Share Posted October 22, 2009 VARCHAR fields also cannot be longer than 255. Quote Link to comment https://forums.phpfreaks.com/topic/178576-sql-key-error/#findComment-941892 Share on other sites More sharing options...
Mchl Posted October 22, 2009 Share Posted October 22, 2009 They can (up to 65536) since MySQL 5.0.3 Quote Link to comment https://forums.phpfreaks.com/topic/178576-sql-key-error/#findComment-941897 Share on other sites More sharing options...
Daniel0 Posted October 22, 2009 Share Posted October 22, 2009 Hmm... oh well. I supposed I should have read the fucking manual. Quote Link to comment https://forums.phpfreaks.com/topic/178576-sql-key-error/#findComment-941900 Share on other sites More sharing options...
lipun4u Posted October 22, 2009 Author Share Posted October 22, 2009 My version is... mysql> select version(); +------------------+ | version() | +------------------+ | 5.1.32-community | +------------------+ 1 row in set (0.02 sec) mysql> If I remove the primary key and not null, everything is fine. What should I do ?? Quote Link to comment https://forums.phpfreaks.com/topic/178576-sql-key-error/#findComment-941923 Share on other sites More sharing options...
Daniel0 Posted October 22, 2009 Share Posted October 22, 2009 Use a numeric primary key, or make it shorter than 767 bytes. Quote Link to comment https://forums.phpfreaks.com/topic/178576-sql-key-error/#findComment-941924 Share on other sites More sharing options...
Mchl Posted October 22, 2009 Share Posted October 22, 2009 If you want urls to be unique, create UNIQUE index in this column (though this might be limited to 767 chars as well) Quote Link to comment https://forums.phpfreaks.com/topic/178576-sql-key-error/#findComment-941928 Share on other sites More sharing options...
Daniel0 Posted October 22, 2009 Share Posted October 22, 2009 I don't think I've ever seen a URL that's a kilobyte long though, so you can safely decrease the size to something more realistic. Quote Link to comment https://forums.phpfreaks.com/topic/178576-sql-key-error/#findComment-941933 Share on other sites More sharing options...
lipun4u Posted October 22, 2009 Author Share Posted October 22, 2009 how much u suggest to keep the length ??? Quote Link to comment https://forums.phpfreaks.com/topic/178576-sql-key-error/#findComment-941937 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.