This walkthrough assumes the following environment:
The IIS Database Manager is installed on your Web Server (<Link to DB Manager download>).
A database server (that could reside on the same physical machine as your web server)
Setting the Stage Up
Let's use a scenario for this walkthrough and assume that we would like to create an access control list for resources on our fictitious site www.fabrikam.com. For that, we will build 2 tables:
The first table, "FabrikamUsers", will contain the user ID, username and email address for each user.
The second table, "AccessControls", will contain a reference to a user ID, a resource URL, and whether the user is allowed access to the resource or not.
Creating a New Table
To create a new table:
Open Internet Information Services (IIS) Manager.
Go to Database Manager and expand your database connection node (For more information on creating connections to a database, see Basics of the IIS Database Manager).
On the 'Tables' node, right click and select 'New Table'.
A new tab will appear in the editor area. Take a moment to get familiar with the buttons on the toolbar:
New Column: allows you to add a new column to the table definition.
Delete Column: allows you to remove an existing column for the table definition.
Indexes/Keys: allows you to define an index or primary key on the table.
Relationships: allows you to define a foreign key relationship on the table.
Save: allows you to save changes to the table.
Click on 'New Column' in the toolbar. A new column is created and a 'Column Properties' pane appears.
In the 'Column Properties', do the following:
Type 'UserId' for the name of the column.
Set 'Allow Nulls' to 'False'.
Set 'Data Type' to 'int'.
Leave 'Default Value' blank.
Set 'IsIdentity' to 'True'.
Let's now make this field a primary key by clicking on the 'Indexes/Keys' icon. A new dialog will open up.
On the dialog, click the 'Add' button and then fill out the information for the primary key as follows:
Set 'Columns' to 'UserId'.
Set 'Is Unique' to 'True'.
Set 'Type' to 'Primary Key'.
Set 'Name' to 'PK_UserId'.
Click 'Close' to close the dialog.
Add another column for the username by clicking on 'New Column' in the toolbar.
In the 'Column Properties', do the following:
Type 'Username' for the name of the column.
Set 'Allow Nulls' to 'False'.
Set 'Data Type' to 'varchar'.
Set 'Length' to 50.
Finally, add another column for the email address by clicking on 'New Column' in the toolbar.
In the 'Column Properties', do the following:
Type 'Email' for the name of the column.
Set 'Allow Nulls' to 'True'.
Set 'Data Type' to 'varchar'.
Set 'Length' to 100.
Click 'Save' on the toolbar, a save dialog opens up.
In the 'Table Name', type 'FabrikamUsers'. You can also specify a schema or leave the 'Schema Name' field empty to use the default schema for your database user.
Now, let us define the 'AccessControls' table. We will follow similar steps to the above:
On the 'Tables' node, right click and select 'New Table'. A new tab will appear in the editor area.
Click on 'New Column' in the toolbar. A new column is created and a 'Column Properties' pane appears.
In the 'Column Properties', do the following:
Type 'ACId' for the name of the column.
Set 'Allow Nulls' to 'False'.
Set 'Data Type' to 'int'.
Leave 'Default Value' blank.
Set 'IsIdentity' to 'True'.
Let's now make this field a primary key by clicking on the 'Indexes/Keys' icon. A new dialog will open up.
On the dialog, click the 'Add' button and then fill out the information for the primary key as follows:
Set 'Columns' to 'ACId'.
Set 'Is Unique' to 'True'.
Set 'Type' to 'Primary Key'.
Set 'Name' to 'PK_ACId'.
Click 'Close' to close the dialog.
Add another column for the referenced user by clicking on 'New Column' in the toolbar.
In the 'Column Properties', do the following:
Type 'UserId' for the name of the column.
Set 'Allow Nulls' to 'False'.
Set 'Data Type' to 'int'.
Set 'IsIdentity' to 'False'.
Add yet another column for the resource by clicking on 'New Column' in the toolbar.
In the 'Column Properties', do the following:
Type 'ResourceURL' for the name of the column.
Set 'Allow Nulls' to 'False'.
Set 'Data Type' to 'varchar'.
Set 'Length' to 200.
Finally, add another column for specifying the access right by clicking on 'New Column' in the toolbar.
In the 'Column Properties', do the following:
Type 'IsUserAllowed' for the name of the column.
Set 'Allow Nulls' to 'False'.
Set 'Data Type' to 'Bit'.
Set 'Default Value' to 'False'.
Click 'Save' on the toolbar, a save dialog opens up.
In the 'Table Name', type 'AccessControls'. You can also specify a schema or leave the 'Schema Name' field empty to use the default schema for your database user.
Modifying an Existing Table
The Database Manager allows you to edit the definition of an existing table. More specifically, you can:
Add, modify or delete new columns.
Add, modify or delete a primary key.
Add, modify or delete a foreign key relationship.
Now that we have created the two tables, "FabrikamUsers" and "AccessControls", let us link them together. We will need to edit the "AccessControls" table and add a foreign key relationship to the "FabrikamUsers" table:
Open IIS Manager and navigate to the Database Manager.
Expand the database connection node in the Database Manager tree view (For more information on creating connections to a database, see Basics of the IIS Database Manager).
Expand the 'Tables' node. You should now see a list of all your database tables, including "FabrikamUsers" and "AccessControls".
Select "AccessControls" and then click 'Open Table Definition' on the toolbar. A table design view opens up and displays the columns that we created in 'Create a New Table'.
On the table design view's toolbar, click on 'Relationships'. The 'Foreign Key Relationships' dialog opens up.
Click Add. A new foreign key relationship editor is displayed.
In the foreign key relationship editor, select the 'Tables and Columns Specifications' and click on the ellipsis '…' button. The 'Tables and Columns' dialog opens up.
In the 'Relationship name' field, type 'FK_AccessControlsForUsers'.
In the 'Primary key table' drop down, select "FabrikamUsers". Now you should see a drop down list of primary keys from the "FabrikamUsers" table. Make sure that "UserId" is selected.
In the second drop down, you should see a list of columns from "AccessControls". Select "UserId" and click OK to close the dialog.
Click Close on the 'Foreign Key Relationships' dialog.
Click 'Save' to update the tables. We now just created a relationship between the "FabrikamUsers" and "AccessControls" tables.
Changing Table Data
The Database Manager allows you to modify data in an existing table. More specifically, you can:
Add new rows.
Modify a value in an existing row (available for supported data types <link to supported data types>).
Delete an existing row.
Let us start populating our "FabrikamUsers" and "AccessControls" table with some user information:
Open IIS Manager and navigate to the Database Manager.
Expand the database connection node in the Database Manager tree view (For more information on creating connections to a database, see Basics of the IIS Database Manager).
Expand the 'Tables' node. You should now see a list of all your database tables, including "FabrikamUsers" and "AccessControls".
Right-click on "FabrikamUsers" and select 'Show Table Data'. You should now see the data inside your table. There should also be a row preceded by a '*' that you can use to enter new data.
In the new row (*), click in the 'Username' column and type 'John Doe'. Next, click on the 'Email' column and type 'JohnDoe@fabrikam.com'.
When you are done entering information for the new row, hit Enter. The information is now saved in the database. Notice that the 'UserId' field is automatically populated with an incremental value since it is marked as an identity.
Add a few more rows of sample user names and email addresses.
Right-click on "AccessControls" and select 'Show Table Data'. You should now see the data inside your table. There should also be a row preceded by a '*' that you can use to enter new data.
In the new row (*), click in the 'UserId' column and type '1'. Entering this UserId value will point to the first record in your "FabrikamUsers" table (which should be 'John Doe' according to our example.
Next, click on the 'ResourceURL' column and type 'admin.aspx' and type 'True' in the IsUserAllowed column. This implies that user 'John Doe' can access the admin.aspx page of our fictitious site.
Add a few more rows of sample access rights for other users.
Now that we have some data in the table, let us modify and delete an existing row:
Click on any table cell that you would like to modify. Type a new value in the cell. Notice that a pencil appears next to the row you are editing.
Click on another cell or close the table to save the information. Notice that the information is saved to the server and the pencil icon disappears.
Now select a row by clicking on the arrow to the left of the row, and then click the 'Delete' button on the toolbar. A dialog asks for confirmation before deleting.
If you select 'Yes', the row of information is deleted on the server.
Administer an SQL Server database infrastructure for cloud, on-premises and hybrid relational databases using the Microsoft PaaS relational database offerings.