New Table Editor - Primary Key possible?

[expired user #4035]'s profile image [expired user #4035] posted 16 years ago in General Permalink
How do you create a Primary Key using the new Table Editor (not an Index). Is it possible?

Have tried: create New Table -> add Table Name, set 1 as auto increment (options tabe), add a column (int(11) unsigned auto_increment) -> then SQL errors. Tried adding an index and dragging and dropping the id column too just for luck... no luck!

Any ideas please?

Thanks

(Version 4 build 2417)
ansgar's profile image ansgar posted 16 years ago Permalink
Just click or F2 the second column, it lets you chose the index type (primary, fulltext, etc.)
1 attachment(s):
  • createpk
[expired user #4035]'s profile image [expired user #4035] posted 16 years ago Permalink
Thanks very much
ansgar's profile image ansgar posted 16 years ago Permalink
Well the table editor is brand new and not yet so perfect. If there are suggestions to enhance it, please post them.

Probably the pulldown editor should be started immidiately when the mouse clicks the cell?
[expired user #4041]'s profile image [expired user #4041] posted 16 years ago Permalink
Ooo I have lots!smileBug's I'll file in the correct place too, but some ideas and reasons behind it I'll post here (since you asked :-))

Suggestion -
Clicking on 'Add' (field) should focus() on the the fields Name field so it's ready for you to type. From here, tab key should do the expected thing. Right now it's taking a lot more clicks to do the same things as the old table creator.

Problem -
New tables need (in my opinion at least) a primary key. You may only do this once per table, but, it used to be just a few clicks (type the field name in left, then click the checkboxes on the right for index, unique, primary, and auto_increment). Takes about two seconds. There is now a whole process required for doing this, this seems a step backwards.

Solution -
Checkboxes down the left hand side of the Columns table at the bottom. Tick one, it becomes your primary key, and is added to the Indexes tab occordingly. Perhaps the same for auto_increment, it makes sense that selecting auto_increment adds (if not exists) an index for it as you cannot have auto_increment field unless it is indexed.

Problem -
Removing the table editor tab from the main window is a pain for me, but mostly one that can be worked around. One thing is that it means that the fields 'comment' field is now further away from the data and query view, which is where I'd be spending most of my time in the app. We use the comment field to short describe the field and it's interactions which is very handy when building a system with other remote people, as does being able to quickly get a list of fieldnames and datatypes... some fields have long names in databases I work in (not by my choice!) and used to be able to copy one into clipboard in just a few clicks (click the table, then the field, press F2 then Ctrl+C, then back to query view). This is now a much lengthier process which involves scanning through the procedures and table on the left, clicking from there etc etc.

Suggestion -
A toolbar button + shortcut key (alt+enter again?) from the tables 'Data' tab to will open up the tables editor. Perhaps even make it available from the Query tab (it's not uncommon to be jumping between the table editor and query tab where I build stored procedures several times in a minute - this used to be a snap, but is now far too lengthy a process for it to be usable). (the reason I do my procedure building in the query editor rather than stored procedure editor is because the convenience of being able to just hit F9 to test the code 'n sytax etc from the query tab)

Bug (briefly) -
Create new table, add new field, set it to auto_incement. Now add another field. This new field defaults to auto_increment, but there can only be one auto_increment field per table.

I can't test it properly as it's producing incorrect SQL (it's producing "ADD PRIMARY KEY (`id`)", the 'ADD' shouldn't be there) but I'm guessing that's known about.

Alex
[expired user #4035]'s profile image [expired user #4035] posted 16 years ago Permalink
I agree with that. A single click would be better.

Can I ask another question?

When I create a table with a primary key, I get the following error:

SQL error: ... ADD PRIMARY KEY (`id`) ) COMMENT '' COLLATE utf8

Having looked at previous SQL syntax generated by Heidi, is the "ADD " keyword in the generated SQL new? If I copy the SQL from the SQL tab, and remove the "ADD" keyword, I can create a table from that SQL ok.

Any thoughts...?

MySQL Version: 5.0.45 runnng on RHEL 5

Thanks


Greg
ansgar's profile image ansgar posted 16 years ago Permalink
The superflous ADD keyword is removed in r2429
ansgar's profile image ansgar posted 16 years ago Permalink
One-click editing in index tree implemented in in r2431
ansgar's profile image ansgar posted 16 years ago Permalink
> Suggestion - Clicking on 'Add' (field) should focus() on the the fields Name
> field so it's ready for you to type

Nice suggestion. Done in r2432
ansgar's profile image ansgar posted 16 years ago Permalink

some fields have long names in databases I work in (not by my choice!) and used to be able to copy one into clipboard in just a few clicks (click the table, then the field, press F2 then Ctrl+C, then back to query view)...



Did you notice the query helpers box on the right? It also holds all columns of the selected table. Column names are drag'n droppable from there.
[expired user #4035]'s profile image [expired user #4035] posted 16 years ago Permalink
Thanks for your help (and a very useful piece of software).
[expired user #4041]'s profile image [expired user #4041] posted 16 years ago Permalink
Did you notice the query helpers box on the right?

No, am confused, where are you referencing?

Nice suggestion. Done in r2432

I do love UI design, is one of the most instantly-rewarding areas of software development as the changes are instantly seen and felt by users. I will soon get hold of development stuff needed for this project (have so far only got as far as svn'ing the tree) to become more familiar with it as would love to help out with some of the development. Until then, a few more you may wish to consider, although I would say not as important as those I listed before.

In table editor, double clicking the blank space in the Fields table (ie, where there are no column rows) to do the same as the Add button. This is like double clicking blank space to the side of browser tabs, which creates a new tab (as what else would double clicking in an empty space mean, other than "I want one here too"?). Pressing Escape on the new field, if no fieldname or changes to it have been made (from the default) could cancel the row, rather than leave a blank "Column 3" etc named field.

When you click the Default cell, which pops open the form that gives you options Text, Null, et. Keeping with consistency of the dropdowns of other fields, selecting Null, Current_timestamp, or Auto_increment would close the popup back up.

Dragging a field from the field table below to an empty index tree above could create a new index to contain that field, rather than ignoring the drop. Perhaps a popup menu on that event, like right-click-dragging a file in Explorer, with items like "Make primary key", "New index", "New unique" etc. Failing that, the first drop to an empty space would most likely want to default to creating it as the primary key.

Have also found bug with pressing Escape in the DEFAULT value selector (posted bug http://code.google.com/p/heidisql/issues/detail?id=1170)
[expired user #4041]'s profile image [expired user #4041] posted 16 years ago Permalink
Did you notice the query helpers box on the right?

Excuse me - I have found this. I'd pushed it out the way to the right (ie, dragged the frame border to the far right) while writing some long code a while back before the Table tab was removed for the new table editor.

Cheers for the reminder that it was there! I've pulled it back out again now :-)

Please login to leave a reply, or register at first.