Make a List
This tutorial shows you a quick way to make a MySQL table using a text editor and Entrance.
Open a text editor, like TextEdit or Notepad, and type in a few lines of text:
apple
pear
plum
cherry
Then
select the lines and copy them to the clipboard. (You can use
Command-A Command-C on the Mac, Ctrl-A Ctrl-C on Windows or Linux to
select all and copy)
Now
open Entrance, go to the Edit menu, and select “Paste data from
clipboard...”. You will see a dialog like this one:
Select
"Simple List" for the data type, then fill in a name for the new table,
say “Fruit”, and click OK. Congratulations, you have created a
table in a database.
Next,
you might want to change the name of the only column in Fruit from
“COL0” to something more descriptive. Here’s how to do that:
Open the column popup menu (Ctrl-Click on column ‘COL0’ on the
Mac, right click on Windows) and select “Rename Column...”. Enter
a new name, something like "Name" will do, and click Ok.
Add to the list
Now type a few more lines in your editor:
lemon
orange
grapefruit
Select these three lines and copy them to the clipboard. Use Entrance to paste them as before.
Notice
that when the dialog opens this time, the table name "Fruit" is already
filled in and "Append rows to existing table" is already selected
(because these values are automatically filled in when you have a table
tab open). Click OK, and the new lines will appear in your table.
Query the list
There
is a quick way to start writing a SQL query on a table. Open its
popup menu from the explorer tree (Right-click or Command-click) and
then click "SQL to select *". This will create a query and open
it. Now you can run the query or edit it to do other
things. For example, try adding a "where clause", like the one in
bold below:
use test;
select * from fruit
where Name like 'p%';
and
then click the Run tool to see what it does. (Answer: This
query selects names beginning with 'p'. The character '%' is a
wildcard)
There
are more details about writing SQL SELECT queries with WHERE clauses
bookmarked under the Help menu. Click "SELECT Syntax" in the Help
menu to learn more.
Creating a list with more than one column
You
can make tables with two or more columns by separating values on a line
with tabs. For example, this text will make a table with two
columns:
1(tab)George Washington
2(tab)John Adams
3(tab)Thomas Jefferson
4(tab)James Madison
Creating a list with given column names
You
can also specify column names. For example, try pasting this data
with the "first line contains column names" checkbox checked:
Which(tab)Name
1(tab)George Washington
2(tab)John Adams
3(tab)Thomas Jefferson
4(tab)James Madison
Avoid sorting problems
The
tables you create this way will all have column types appropriate for
storing strings up to 255 characters long. These column types
work just fine for simple things like address books and mailing lists.
Arithmetic operations and functions like sum() and max()
will work, too.
However,
if you are working with numbers, you will want to change their column
type from text to a number type, so that they sort correctly.
Here's how to do that. Open the column popup in the table
window and select "Change column type...":
Then
select "integer" or another of the number types. Now you can
bring up the column popup again, and this time select a sorting option.
Rows will sort correctly.
Getting back to SQL
Most
operations in Entrance are designed to make it easy to get "back" to
the SQL script underlying them, so that a MySQL developer can do fine
tuning if it is needed. To get a MySQL create table script
matching the tables you create using these techniques, go to the
Entrance explorer tree, open the popup on the corresponding table node,
and select "SQL to create table".
Please
note: This web page and other Entrance documentation web pages
are copyrighted material and have not been released under the terms of
the GPL.
Copyright
(c) Tod Landis 2006,2007 All Rights Reserved
Modified: May 31, 2007
MySQL
is a registered trademark of MySQL AB in the United States, the
European Union and other countries. Windows is a trademark of
Microsoft Corporation. Macintosh is a trademark of Apple
Computer, Inc.