December 5, 2013 at 12:17 pm
I have a table tbl_rules.
This table will define rules for each role. I have not yet defined the fields for the rules. But the table definition is as below:
Create table tbl_Rules
(
ID int identity(1,1) not null,
Role_ID int not null,
primary key (ID),
constraint fk_RoleName foreign key (Role_ID)
references tbl_Role(ID)
)
The table tbl_role has two columns as below:
ID RoleName
1 Manager
2 Analyst
3 Admin
So far so good. I created the tbl_rules.
But what i want to do is when I do select * from tbl_Rules, i want to show as below:
ID Role_ID
1 Manager
2 Admin
Instead it shows
ID Role_ID
1 1
2 3
Is there a way to do this?
The goal is to return the select * from tbl_Rules results to a gridview to enable adds and changes.
I could do this by doing queries for each column, but I was hoping to make it easier.
Not sure if this is even possible.
Thanks much,
Tina
December 5, 2013 at 12:31 pm
Tina there's quite a few things i'd do differently as far as the naming of tables and columns; Tables don't need tbl_ in front of the name, and the PK of the table, should include the table name: ie tbl_roles should be Roles, and have a PK Name RoleID(no underscores), and the FK columns hsould be the exact same name.
for the usability like you were asking, you could add a view , instead of the table itself
select * from vw_Rules
CREATE VIEW vw_Rules
AS
SELECT
T1.ID,
T1.RoleID,
T2.RoleName
FROM tbl_Rules T1
LEFT OUTER JOIN tbl_role T2
ON T1.RoleID = T2.ID
Lowell
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply