When you get into it, SQL commands are pretty powerful. You can add, edit and delete pieces of data at whim. The command to create tables to hold this data is create while working in a relational database management system(RDBMS). ..What was that noise? The sound of your MIND BLOWING? Ha, but seriously, in a lot of cases commands can be pretty self descriptive. Create requires a few details:
- the name of the table you’re going to create
- names for each of the fields(remember, fields are represented by columns in database tables)
- definitions for each field (what data type the field’s values will be in)
Let’s go through a quick example. Feel free to copy the following into MySQL or other RDBMS and run these queries.
create database pokedex;
use pokedex;
create table pokemon (
pokemon_id int NOT NULL PRIMARY KEY,
pokemon_name varchar(50),
no_evolutions int
);
select * from pokemon;
In the first line, I create my new database-Pokedex. Keep in mind that you have to specify which database you are using with the use keyword before you create your new table or it will be created in the last used database.
Next we get down to creating our table! We call the table pokemon’ and within the parentheses we specify our column names; pokemon_id, pokemon_name and no_evolutions. Following the name of each column we tell the table what kind of data values will be stored in it. If you run this complete query sequence in MySQL, you will see your new table created with the rows you specified in your result grid view!
