0% found this document useful (0 votes)
66 views

Dbms Lab 6 PDF

The document discusses creating a database called ABC_Employees in SQL Server Management Studio. Six tables - dept_emp, salaries, departments, employees, dept_manager, and titles - are created with various attributes and data types. Relationships between tables are defined using primary and foreign keys. Data is inserted into the tables, and selected from the tables. Creating databases and tables, inserting and selecting data is easier using the visual SQL Server Management Studio than command lines.

Uploaded by

Cassie Cutie
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views

Dbms Lab 6 PDF

The document discusses creating a database called ABC_Employees in SQL Server Management Studio. Six tables - dept_emp, salaries, departments, employees, dept_manager, and titles - are created with various attributes and data types. Relationships between tables are defined using primary and foreign keys. Data is inserted into the tables, and selected from the tables. Creating databases and tables, inserting and selecting data is easier using the visual SQL Server Management Studio than command lines.

Uploaded by

Cassie Cutie
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Laboratory Act.

6 – Introduction to SQL Server Environment


Simbulan, Ryan C. 08/12/2019
CPE011/ CPE21FB3 Engr. Royce B. Chua

I. SCREENSHOTS AND OBSERVATION

1. Create a database ABC_Employees.

To create a database in the Microsoft SQL Server Management Studio, first open the software, open
the object explorer and connect it to the SQL server. After these steps, click the server name which is at the
top of the dialog box, after clicking this, a list of folders will appear, right click on databases folder and select
new database. A dialog box will appear and here, you can enter the name of your database, which is in this
case is ABC_Employees.

2. Create the following tables in the ABC_Employees database.


2.1 Create table dept_emp

To create a table, do the steps dictated on the step 1, after that, click the database created and a list
of folders will appear below it, one of which is Tables, click the right click on the folder Tables and click new,
after it, click table. A window will appear (appearing as a new environment/tab), here, you can list the
attributes of the table you want to create and the data types on the second column, you can modify the
attribute if it will allow null values by checking the box on the 3rd column. The attributes, their corresponding
types and allowance of null is shown on the image above. To save this, enter Ctrl+s and a dialog box will
appear asking for the table name (dept_emp).

2.2 Create table salaries

The same steps are done to create a new table (steps 1-2.1), the attributes, their corresponding
types and allowance of null values are shown above. As for setting a primary key on this table, right click on
the attribute from_date, click set primary key. To save this, enter Ctrl+s and a dialog box will appear asking
for the table name (salaries).

2.3 Create table departments

The same steps are done to create a new table (steps 1-2.1), the attributes, their corresponding
types and allowance of null values are shown above. As for setting a primary key on this table, right click on
the attribute dept_no, click set primary key. To save this, enter Ctrl+s and a dialog box will appear asking for
the table name (departments).

2.4 Create table employees

The same steps are done to create a new table (steps 1-2.1), the attributes, their corresponding
types and allowance of null values are shown above. As for setting a primary key on this table, right click on
the attribute emp_no, click set primary key. To save this, enter Ctrl+s and a dialog box will appear asking for
the table name (employees).
2.5 Create table dept_manager

The same steps are done to create a new table (steps 1-2.1), the attributes, their corresponding
types and allowance of null values are shown above. To save this, enter Ctrl+s and a dialog box will appear
asking for the table name (dept_manager).

2.6 Create table titles

The same steps are done to create a new table (steps 1-2.1), the attributes, their corresponding
types and allowance of null values are shown above. As for setting a primary key on this table, right click on
the attribute title, click set primary key. To save this, enter Ctrl+s and a dialog box will appear asking for the
table name (titles).

3. Create relationships using the database diagram.


To create a diagram, follow step 1 and under the created database, click Database Diagram, a dialog
box will appear asking for permission, click Yes right click on the database diagram and select New. A dialog
box will appear asking for the tables to be inserted, select all. You can create foreign keys by referencing
primary keys from other tables. You can reference foreign keys by dragging the primary key from the other
table that would be used as a foreign key to the table where it will be used. A dialog box will appear displaying
the location and name of the primary key and asking for the attribute name that would be used as a foreign
key, select which and click ok.
After doing the steps above, for the table dept_emp, the primary key from table employees was
dragged into the dept_emp and was set as foreign key with constraint name emp_no, the primary key from
table departments is dragged into the dept_emp and was set as a foreign key with constraint name dept_no.
For the table Salary, the primary key is the attribute from_date, the primary key from table employees was
dragged into the salary and was set as as a foreign key with constraint name emp_no. For the table
departments, the primary key is attribute dept_no. For the table employees, the primary key is emp_no. For
the table dept_manager, the primary key from table employees was dragged into the dept_emp and was set
as foreign key with constraint name emp_no, the primary key from table departments is dragged into the
dept_emp and was set as a foreign key with constraint name dept_no. For the table titles, the primary key is
attribute title, the primary key from table employees was dragged into the salary and was set as a foreign key
with constraint name emp_no.

4. Insert 10 Employees with their salary, department and their manager.


To insert values in the created tables, right click on the table you want to insert values to,
click Edit Top 200 Rows, a new tab will open displaying the attributes of each table with blank rows
below, there you can insert the values desired.

4.1 Insert values in table dept_emp

For the table dept_emp, 10 rows have been inserted with values in columns emp_no and dept_no
referenced to the primary keys emp_no and dept_no from tables employees and departments, respectively.
4.2 Insert values in table salaries

For the table salary, 10 rows have been inserted with values in column emp_no referenced to the
primary key emp_no from table employees. The primary key is from_date.

4.3 Insert values in table departments

For the table department, 4 rows have been inserted since each employee is not necessarily limited
to a single department. (e.g. 3 employees can be in 1 department). The primary key is dept_no.

4.4 Insert values in table employees

For the table employees, 10 rows have been inserted with columns birth_date and hire_date set to
null to show that how the allowance of null values in the process of creating a table works. The primary key
is emp_no.
4.5 Insert values in table dept_manager

For the table dept_manager, 4 rows have been inserted since usually, a single department has only
1 manager. As for the foreign keys, 4 rows have been inserted with values in columns emp_no and dept_no
referenced to the primary keys emp_no and dept_no from tables employees and departments, respectively.

4.6 Insert values in table titles

For the table titles, 10 rows have been inserted since each employee has different titles. As for the
foreign key, 10 rows have been inserted with values in column emp_no referenced to the primary key emp_no
from table employees. The primary key is title.
5. Select and view the data in the tables of ABC_EmployeesDB database.
To select values in the created tables, right click on the table you want to select values from,
click Select Top 200 Rows, a new tab will open displaying the attributes of each table with values
below.

5.1 Select table dept_emp


5.2 Select table salary

5.3 Select table departments


5.4 Select table employees
5.5 Select table dept_manager

5.6 Select table titles


II. SUMMARY
It is valid to say that the creation of tables, insertion and selection of values is much
easier if one uses the software Microsoft SQL Server Management Studio. To create a database,
click on connect the Management Studio to the SQL Server, after that, the server name will
appear on the Object Explorer tab, click it and a list of folders will appear in in which folder
Database is included, right click the folder Database and click New Database and name it. For
the creation of tables, click the created database and a list of folders will appear in which Tables
is included, right click the folder Tables and click new, click table. For Insertion of values, right
click on the created tables and select Edit Top 200 Rows. For the Selection of tables, right click
on the tables with inserted values and click Select Top 200 Rows.

III. CONCLUSION
Using a third party software in creating databases is more efficient and time-saving
more than MySQL xampp since it is more visual and is easier to understand than hard coded
commands in command lines. This is due to the user-friendly nature of the software.
IV. RECOMMENDATIONS
Users are recommended to carefully create the tables and its attributes since the
mistakes are irredeemable, an error will occur if the user tries to rename an attribute referenced
from other tables.

V. LESSONS LEARNED
• The relationships created using the database diagram can be deleted and modified.
• Errors may occur if one tries to rename a referenced attribute.
• The protocol in connecting the object explorer in the SQL server is a little complicated,
sometimes the server name does not appear which requires the user to run through cmd
to retrieve it.

You might also like