First, let us create a new database with the name walmart.
We are trying create a department table for walmart as it has many departments and each department is under a division.
Now we can see that database got created
Next, we will create table under this database. From the dropdown menu on the top, selects tools and then select Query Tool
It will open new window where we can write SQL code. We are going to name this table as departments and we want 2 columns in it- department and division.
Another important thing to note is we want department column to be the primary key. There can be only 1 primary key and it acts as a constraints for the column. It prevents any duplicate or null values in the column as it is unique key.
A good practice is to keep some margin for future purpose. May be the list you have right now is showing all small department names but in future if a new department with longer name needs to be created then you should have enough room in your column to allow it.
And we can see under walmart database schema, that the table with the name departments is there now.
At the moment we have created empty table without any entry in any of its rows. Something like this...
Next, we will add data in these columns. We have already prepared data to be entered in this table.
We will always confirm after executing the query that it was successful.
And if we want to see how departments table looks like, we can check that now.
Using this we can create as many tables we need under this database.
No comments:
Post a Comment