Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How implement object orientation features in sql server?


How implement object orientation features in sql server?

Author
Message
tz.bahrami
tz.bahrami
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 13
I know features of object orientation could not implemented, but i want to find a way to implement them. For example for implementing inheritance we can use foreign key.
Please help me to find some ways for encapsulation and other features.
Sean Lange
Sean Lange
SSCoach
SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)

Group: General Forum Members
Points: 19052 Visits: 17198
tz.bahrami (12/26/2012)
I know features of object orientation could not implemented, but i want to find a way to implement them. For example for implementing inheritance we can use foreign key.
Please help me to find some ways for encapsulation and other features.


Can you rephrase your question? I don't understand what you are asking here at all.

How can you a foreign key to implement inheritance?

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
GilaMonster
GilaMonster
SSC Guru
SSC Guru (57K reputation)SSC Guru (57K reputation)SSC Guru (57K reputation)SSC Guru (57K reputation)SSC Guru (57K reputation)SSC Guru (57K reputation)SSC Guru (57K reputation)SSC Guru (57K reputation)

Group: General Forum Members
Points: 57897 Visits: 44708
tz.bahrami (12/26/2012)
I know features of object orientation could not implemented, but i want to find a way to implement them.


Only advice I can give you there is don't. SQL is not an object database. You may be able to force some object stuff into the DB if you hammer hard enough, doesn't make it a good idea.

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Bill Talada
Bill Talada
Mr or Mrs. 500
Mr or Mrs. 500 (573 reputation)Mr or Mrs. 500 (573 reputation)Mr or Mrs. 500 (573 reputation)Mr or Mrs. 500 (573 reputation)Mr or Mrs. 500 (573 reputation)Mr or Mrs. 500 (573 reputation)Mr or Mrs. 500 (573 reputation)Mr or Mrs. 500 (573 reputation)

Group: General Forum Members
Points: 573 Visits: 1870
Only expose stored procedures as the interface to the front end. Do whatever you like behind the scenes. It is about as object oriented as you can get with a database.
Orlando Colamatteo
Orlando Colamatteo
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10493 Visits: 14376
Here is some available reading on the topic that may help you gain a deeper understanding of what things to consider before implementing your database:

Object-relational impedance mismatch, From Wikipedia

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
tz.bahrami
tz.bahrami
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 13
In inheritance a child table can gain father's features, so if i add child table's primary key to father's table as foreign key, it can gain father's features it is like inheritance.is'nt it?
Bill Talada
Bill Talada
Mr or Mrs. 500
Mr or Mrs. 500 (573 reputation)Mr or Mrs. 500 (573 reputation)Mr or Mrs. 500 (573 reputation)Mr or Mrs. 500 (573 reputation)Mr or Mrs. 500 (573 reputation)Mr or Mrs. 500 (573 reputation)Mr or Mrs. 500 (573 reputation)Mr or Mrs. 500 (573 reputation)

Group: General Forum Members
Points: 573 Visits: 1870
tz.bahrami (12/27/2012)
In inheritance a child table can gain father's features, so if i add child table's primary key to father's table as foreign key, it can gain father's features it is like inheritance.is'nt it?


That would limit you to one child. If you make a "join" table between them, it will allow you to have many children or parents. A join table row would contain keys for the parent and child.

Once again...if you use stored procedure calls you can encapsulate everything, hide implementation, and have loose coupling. Think of stored procedures as method calls.
tz.bahrami
tz.bahrami
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 13
Thanks for your instruction, i am familiar with junction table, but i look a way to implement something like inheritance. In addition i agree with you for encapsulating by stored procedures.
Sean Lange
Sean Lange
SSCoach
SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)

Group: General Forum Members
Points: 19052 Visits: 17198
tz.bahrami (12/27/2012)
Thanks for your instruction, i am familiar with junction table, but i look a way to implement something like inheritance. In addition i agree with you for encapsulating by stored procedures.


Your request still doesn't make sense. If you MUST think of sql as objects think of the table as the object and each row as the instance and each column is the property. What you are describing is you want to inherit the row. This doesn't make sense because in OOP that would be like inheriting the properties of an instance. It doesn't work like that. You inherit the object.

I think that what you are really trying to do is to have a parent - child relationship in sql. This of course is not only possible, it is a fundamental base for normalized data.

Is the following example something along the lines of what you talking about?


create table #Parent
(
ParentID int identity,
SomeValue varchar(10)
)

create table #Child
(
ChildID int identity,
ParentID int,
SomeValue varchar(10)
)

insert #Parent
select 'Parent 1' union all
select 'Parent 2'

insert #Child
select 1, 'Child 1' union all
select 1, 'Child 2' union all
select 2, 'Child 3' union all
select 2, 'Child 4' union all
select 2, 'Child 5'

select *
from #Parent p
join #Child c on p.ParentID = c.ParentID

drop table #Parent
drop table #Child



_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Bill Talada
Bill Talada
Mr or Mrs. 500
Mr or Mrs. 500 (573 reputation)Mr or Mrs. 500 (573 reputation)Mr or Mrs. 500 (573 reputation)Mr or Mrs. 500 (573 reputation)Mr or Mrs. 500 (573 reputation)Mr or Mrs. 500 (573 reputation)Mr or Mrs. 500 (573 reputation)Mr or Mrs. 500 (573 reputation)

Group: General Forum Members
Points: 573 Visits: 1870
You can create views to "merge" two tables but they get tricky when you try to update columns from both tables.

You could create a wide table (sparse) containing all the sub-types as nullable columns and implement views on it to give you your subset that you can update.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search