jp2php Posted July 13, 2009 Share Posted July 13, 2009 I've got to run a basic "CREATE TABLE" statement. I'm most familiar with SQL Server, but this statement needs to also run on MySQL and Microsoft Access. The statement below should create the table, but I don't know how to tell it that the UserID needs to be my primary key. Also, I'm not sure if other table formats use the same variable names. Is "int" standard accepted SQL, or do some tables require "Number" or "Integer"? (The reason I ask is because I opened an Access table in Design View, it lists Integer fields as "Number" and Boolean fields as "Yes/No".) Here's what I want to crank out: CREATE TABLE Users ( UserID int, -- AutoNumber UserName varchar(255), Hash1 varchar(255), -- SHA1 Encrypted Password Firstname varchar(255), Lastname varchar(255), Email varchar(255), Hint varchar(255), -- Challenge prior to resetting PWD Hash2 varchar(255), -- SHA1 Encrypted Hint response Active bit, -- Set after person verifies with link sent StartDate DateTime, -- Date account was created LastUse DateTime, -- Date account was last used Level int -- 1=Admin, 2=PowerUser, 3=Regular, 4=Guest ) It is probably obvious from the format I'm using what this table is going to be for. If anyone is thinking, "Hey brother, here's this example that shows everything you want all wrapped up in little package" .. I'm interested! The thought of writing forms for them to create their accounts with, SHA1 their data, send email challenges, activate them on replies, keep track of their dates, etc. seems like a lot of debugging, to me. Quote Link to comment https://forums.phpfreaks.com/topic/165750-solved-create-table/ Share on other sites More sharing options...
kickstart Posted July 13, 2009 Share Posted July 13, 2009 Hi Had a quick play and this will give you the primary key:- CREATE TABLE Users ( UserID int, -- AutoNumber UserName varchar(255), Hash1 varchar(255), -- SHA1 Encrypted Password Firstname varchar(255), Lastname varchar(255), Email varchar(255), Hint varchar(255), -- Challenge prior to resetting PWD Hash2 varchar(255), -- SHA1 Encrypted Hint response Active bit, -- Set after person verifies with link sent StartDate DateTime, -- Date account was created LastUse DateTime, -- Date account was last used Level int -- 1=Admin, 2=PowerUser, 3=Regular, 4=Guest PRIMARY KEY (`UserID`) ) Works in both MySQL and Access All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/165750-solved-create-table/#findComment-874493 Share on other sites More sharing options...
jp2php Posted July 13, 2009 Author Share Posted July 13, 2009 Thanks Keith, I don't have a personal MySQL db to test on. The company as a whole has something for testing, but I don't want to go in there and break it with a simple 'Create Table' query. A quick follow-up before you are gone. In this line: PRIMARY KEY (`UserID`) Do I need to use reverse single quotes (i.e. the key to the left of #1 on the keypad) or is that just a preference? Quote Link to comment https://forums.phpfreaks.com/topic/165750-solved-create-table/#findComment-874508 Share on other sites More sharing options...
kickstart Posted July 13, 2009 Share Posted July 13, 2009 Hi For MySQL probably just easiest to download a packages WAMP setup (assuming Windows) such as this The back ticks are a default in phpMyAdmin, and useful if you want a column name which is otherwise a reserved word. Personally I prefer not to use them, and just be careful with column names. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/165750-solved-create-table/#findComment-874513 Share on other sites More sharing options...
jp2php Posted July 13, 2009 Author Share Posted July 13, 2009 Hey, thanks for the link! I've been looking for something I could use as an interface like that. So basically, "the back ticks" would be like including the names in "square brackets", which is something I have to do with SQL Server: SELECT [Name], [Group], [Count] FROM EmployeeTable Are square brackets OK in MySQL as well as back ticks? It may seem like a stupid question, but I want to make sure I don't fowl up the database. Quote Link to comment https://forums.phpfreaks.com/topic/165750-solved-create-table/#findComment-874517 Share on other sites More sharing options...
kickstart Posted July 13, 2009 Share Posted July 13, 2009 Hi Honestly do not know for sure. It doesn't appear to accept square brackets, but not sure if their might be a configuration option somewhere. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/165750-solved-create-table/#findComment-874523 Share on other sites More sharing options...
fenway Posted July 15, 2009 Share Posted July 15, 2009 No, square brackets are not ok. Quote Link to comment https://forums.phpfreaks.com/topic/165750-solved-create-table/#findComment-876111 Share on other sites More sharing options...
jp2php Posted July 16, 2009 Author Share Posted July 16, 2009 No, square brackets are not ok. Thanks for the help, fenway. Quote Link to comment https://forums.phpfreaks.com/topic/165750-solved-create-table/#findComment-876193 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.