You are on page 1of 2

1

Laboratory Exercise 1: Creating Databases and Tables

1. Click the Create a new schema in the connected server button.


2. Type sampledb for the name of your database then, click Apply. Click Apply again.
3. If there is no problem encountered, a success message will be displayed. Click Finish.
4. Your newly created database will now appear under Schemas. If not, click the Refresh button.
5. Double-click the name of your database to select it.
6. To add a new table, click the Create a new table in the active schema in the connected server
button.
7. Type members for the table name.
8. Double-click on the space under column name and type member_id.
9. Leave the Datatype as INT.
10. The column member_id will serve as the primary key of the members table so click the PK
checkbox.
11. Also, check the NN (NOT NULL) checkbox to require a value for this column and the AI (Auto-
Increment) checkbox to automatically generate value for the column during the creation of each
new record.
12. Double-click the space under member_id (Column Name) then type username.
13. For the data type, use VARCHAR(12). 12 stands for the maximum length of the username value.
14. Check the NN checkbox. You must also check the UQ checkbox to require a unique value for this
column for each record.
15. On your own, add the following columns to your members table:
Column Name Data Type Checkboxes
Email VARCHAR(50) NN, UQ
Password VARCHAR(40) NN

16. If you made a mistake and wants to delete a column, right-click on a column and select Delete
Selected.
17. When you’ve finished adding all columns, click Apply.
18. You will be asked for confirmation. Click Apply once more.
19. If all is well, a success message will be displayed. Click Finish.
20. If you expand Tables under sampledb, you should now see the members table.
21. If you’ve made a mistake or want to add columns to an existing table, right-click on the table
name then, select Alter Table. Don’t forget to click the Apply button after you make your
changes.
22. Add the following columns to the members table.
Column Name Data Type Checkboxes Default
reg_date DATETIME NN CURRENT_TIMESTAMP
member_level TINYINT(2) NN

23. Add a new table named forum with the following columns:

Fundamentals of Information Management and Database Systems


COMTEQ COMPUTER AND BUSINESS COLLEGE
2

Column Name Data Type Checkboxes Default


post_id INT PK, NN, AI
member_id INT NN
Subject VARCHAR(60) NN
Message TEXT NN
post_date DATETIME NN CURRENT_TIMESTAMP

24. Click the Foreign Keys tab.


25. Type any Foreign Key Name (example: fk1).
26. For the referenced table, select ‘sampledb’.’members’. Check the member_id column then,
select the member_id for the referenced column.
27. For the Foreign Key Options, select Cascade for both On Update and On Delete. Click Apply.
28. Click Apply once again then, click Finish.
29. Add another table named test with only one column, id.
30. If you want to delete a table, right-click a table then select Drop Table.
31. Click Drop Now to confirm deletion.
32. You should NOT do this now but just for your information, you may delete a database by right-
clicking on a database and selecting Drop Schema.

Fundamentals of Information Management and Database Systems


COMTEQ COMPUTER AND BUSINESS COLLEGE

You might also like