sasori Posted August 23, 2008 Share Posted August 23, 2008 im practicing to build a database, i was building a customerorderinfo database with 3 tables - customer table - item table - item_order table but am having problem creating a datetime in the item_order table here's my supposed to be syntax in item_order table CREATE TABLE item_order ( cust_id BIGINT, item_order SERIAL, date <--- this is the part i don't know what to place LOL ??? Quote Link to comment Share on other sites More sharing options...
Hooker Posted August 23, 2008 Share Posted August 23, 2008 This will enter the current date/time when the record is inserted: date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP Two other points though, unless you're going to have over 2 billion customers, BIGINT is unessisary and is bad practice as far as mysql performance goes. "SERIAL" is just an ALIAS for BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE, so again.. look into INT or TINYINT Quote Link to comment Share on other sites More sharing options...
sasori Posted August 23, 2008 Author Share Posted August 23, 2008 This will enter the current date/time when the record is inserted: date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP Two other points though, unless you're going to have over 2 billion customers, BIGINT is unessisary and is bad practice as far as mysql performance goes. "SERIAL" is just an ALIAS for BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE, so again.. look into INT or TINYINT thanks for the tips sir.. but what about the YYYY-MM-DD and HH:MM:SS thing goes ? Quote Link to comment Share on other sites More sharing options...
Hooker Posted August 23, 2008 Share Posted August 23, 2008 by default MYSQL will use the format the current date/time to YYYY-MM-DD HH:MM:SS in the column when you do the insert, you can remove the "DEFAULT CURRENT_TIMESTAMP" and look up how to change the format around here if nessisary: http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html Quote Link to comment Share on other sites More sharing options...
sasori Posted August 23, 2008 Author Share Posted August 23, 2008 sir i got another question about that null thing.. should i set primary keys as NULL or NOT NULL ? Quote Link to comment Share on other sites More sharing options...
Hooker Posted August 23, 2008 Share Posted August 23, 2008 primary keys need to be NOT NULL because they're unique keys. Quote Link to comment 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.