Creating Table In Mysql |
|
March 22, 2008 |
This is just something that annoys me at times. In mysql you can typically type:
Show create table TableName, and it will show you the code to create that table.
Probably is they use single quotes which won’t work if you type in that code. So to actually give people a real working version of the create table version, here ya go:
Create TABLE users (
User_ID int(11) NOT NULL auto_increment,
Name varchar(60) NOT NULL,
CreatedOn TIMESTAMP default NOW(),
About Text,
Video_ID int(20),
Primary Key (User_ID),
Unique Key (Name),
Constraint users_ibfk_1 Foreign Key (Video_ID) references video (Video_ID) on Delete Set NULL
) ENGINE=InnoDB Default CharSet=utf8;
Well hopefully that helps. Basically… you don’t use the single quotes at all! Anyway, that’s just a general example, and not that I do highly HIGHLY recommend using UTF8 ALWAYS for databases. Never know when you’ll need unicode support in the future.



March 22, 2008
Leave a Reply