2012年2月21日 星期二

Creating Schemas and Tables

We installed the MySQL database on a Windows platform few days ago.

Now we’ll do something to the database. Let me show you how to create a new schema, and tables.

Create Schema

Launch MySQL Workbench 5.2 CE

image

Edit Table Data

image

Choose Stored Connection, you should see only one for now. Next.

image

For now, we cannot add the schema through this wizard, let’s pick test first, then Finish.

image

The SQL Editor appeared.

image

Right click on schema test, and choose Create Schema

image

Give the name of the schema, in my case is stock_schema, then Apply

image

The sql statement is displayed, then Apply.

image

The SQL script was successfully applied to the database, then Finish.

image

Create Table

You’ll see a new schema appeared in the left, close the create schema window by click on the X

image

Now, we need to create a table. Right click on the Tables(Expand the arrow of your schema, then you’ll see it) , then Create Table…

image

Give the table name and the column name, for this column (Stock_Info_ID) I want a number generated by the database, so I checked the Auto Increment. Please do NOT Apply yet.

image

Scroll down a little bit, then you can add another column here.This column I’m putting the Stock_Code and it’s Unique and Not null. Then Apply.

image

Again, the SQL Statement appeared. Apply to continue.

image

Finish

image

You’ll see one table under Tables

image

Now let’s put some data in the table. Right click on your table and then Edit Table Data.

image

Because the Stock_Info_ID is Auto Increment, so I just put the Stock_Code and then Apply.

image

The SQL Statement appeared again, then Apply.

image

The script was successfully applied, then Finish.

image

You’ll see the Stock_Info_ID was filled automatically.

image

Summary

Now we’ve have a new schema and a new table under this schema. Next time I’ll create another table put these two tables into a view. See you.

沒有留言:

張貼留言

Your comments are welcome, thank you.