Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

How implement object orientation features in sql server? Expand / Collapse
Author
Message
Posted Wednesday, December 26, 2012 1:01 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: 2 days ago @ 6:17 AM
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.
Post #1400347
Posted Wednesday, December 26, 2012 1:09 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 3:28 PM
Points: 13,138, Visits: 11,977
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)
Post #1400353
Posted Wednesday, December 26, 2012 1:13 PM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 4:03 PM
Points: 42,485, Visits: 35,554
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 2008, MVP
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

Post #1400356
Posted Wednesday, December 26, 2012 2:14 PM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Yesterday @ 9:18 PM
Points: 128, Visits: 823
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.
Post #1400375
Posted Wednesday, December 26, 2012 4:30 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 6:48 AM
Points: 7,094, Visits: 12,581
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
Post #1400412
Posted Thursday, December 27, 2012 2:49 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: 2 days ago @ 6:17 AM
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?
Post #1400520
Posted Thursday, December 27, 2012 7:09 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Yesterday @ 9:18 PM
Points: 128, Visits: 823
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.
Post #1400610
Posted Thursday, December 27, 2012 8:20 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: 2 days ago @ 6:17 AM
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.
Post #1400629
Posted Thursday, December 27, 2012 8:32 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 3:28 PM
Points: 13,138, Visits: 11,977
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)
Post #1400637
Posted Thursday, December 27, 2012 8:32 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Yesterday @ 9:18 PM
Points: 128, Visits: 823
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.

Post #1400638
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse