473,405 Members | 2,415 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

quick question on SQL server and object support

Hi folks
I am not at all an SQL server guy (more of an Oracle developer.)
I wanted to know if you guys could tell me if SQL Server supports
objects in the database. If so, could you kindly point me to a
doc or a very quick overview of main object features?

Many thanx!

Jul 23 '05 #1
8 1210

"Menon" <rm*******@gmail.com> wrote in message
news:11**********************@l41g2000cwc.googlegr oups.com...
Hi folks
I am not at all an SQL server guy (more of an Oracle developer.)
I wanted to know if you guys could tell me if SQL Server supports
objects in the database. If so, could you kindly point me to a
doc or a very quick overview of main object features?

Many thanx!


That depends on what you mean by 'support' and 'object'. If you mean storing
large binaries, then yes - you can use the image data type to store up to
2GB of binary data in a row. If you mean instantiating an object written in
some particular language from TSQL then you can use the sp_OA% procedures to
manipulate COM objects, although the objects themselves are not in the
database, they're external.

If you mean anything more advanced than that, then you'll probably have to
wait for MSSQL 2005, which includes the .NET CLR, so you can write code
(stored procedures) in C# or VB in addition to TSQL, and use .NET assemblies
to define your own data types, aggregate functions and so on.

Simon
Jul 23 '05 #2
Thanx Simon.
By objects, I meant ability to create objects in your procedural
code (written in T-SQL.)

I can tell you what Oracle provides. In PL/SQL (Oracle's procedural
language), you can create objects (similar to objects in your
language.) You can even store these objects in what
are called object tables. Is this capability
available in SQL Server. Is there public documentation on this
available ?

Jul 23 '05 #3
Menon (rm*******@gmail.com) writes:
I can tell you what Oracle provides. In PL/SQL (Oracle's procedural
language), you can create objects (similar to objects in your
language.) You can even store these objects in what
are called object tables. Is this capability
available in SQL Server. Is there public documentation on this
available ?


In SQL 2000, no.

In SQL 2005, currently in beta, yes. If you are an MSDN Unviersal
subscriber, you can download the full SQL 2005 from MSDN Subscriber Downloads. Everyone can download the beta of the SQL Express edition
from http://msdn.microsoft.com/SQL/.
I'm not really sure how much of the SQL 2005 Books Online that is
publicly available. In any case, this white paper could be a start:
http://msdn.microsoft.com/sql/2005/2...lrguidance.asp
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #4
Thanx Erland,
That answers my question - I will also check out the links you pointed
to.

Best Regards
Menon

Jul 23 '05 #5
Folks
Can someone please give a really quick syntax of creating and using
objects
(Say, in T-SQL in 2005)
An example to do this In Oracle (using sql*plus - a command
line utility to execute SQL and PL/SQL (the stored procedure language
of Oracle ) is shown below:

-- first we create the type that represents the object interface:
scott@ORA10G> create or replace type employee as object
2 (
3 name varchar2(50),
4 phone varchar2(20),
5 emp_id number,
6 constructor function employee return self as result,
7 constructor function employee( name in varchar2,
8 phone in varchar2, emp_id in number )
9 return self as result,
10 member function get_name return varchar2,
11 member procedure set_name( p_name in varchar2 ),
12 -- other getters and setters
13 static procedure demo_static_proc
14 )
15 not final;
16 /

Type created.

-- next we create the type body that implements any methods declared
-- in the type interface we created above:

scott@ORA10G> create or replace type body employee
2 as
3 constructor function employee return self as result
4 is
5 begin
6 self.name := null;
7 self.phone := null;
8 self.emp_id := null;
9 return;
10 end;
11
12 constructor function employee( name in varchar2,
13 phone in varchar2, emp_id in number )
14 return self as result
15 is
16 begin
17 self.name := name;
18 self.phone := phone;
19 self.emp_id := emp_id;
20 return;
21 end;
22
23 member function get_name return varchar2
24 is
25 begin
26 return name;
27 end;
28
29 member procedure set_name( p_name in varchar2 )
30 is
31 begin
32 name := p_name;
33 end;
34 -- define other getters and setters here (deleted for brevity)
35 static procedure demo_static_proc
36 is
37 begin
38 dbms_output.put_line ( 'This is a simple Oracle object type
that encapsulates a employee.');
39 end;
40 end;
41 /

Type body created.

Following is an example showing initialization of a variable of type
employee
in PL/SQL. Note that we can store employee object directly in tables
as well (not shown)

scott@ORA10G> declare
2 l_employee employee;
3 begin
4 l_employee := employee( 'Joe', '555-666-3345', 1 );
5 dbms_output.put_line( l_employee.name );
6 end;
7 /
Joe

PL/SQL procedure successfully completed.

If some one can show how to do the above (or another euivalent)
in T-SQL in SQL 2005, it would be great.

Many thanx!

Jul 23 '05 #6
Menon (rm*******@gmail.com) writes:
Can someone please give a really quick syntax of creating and using
objects
(Say, in T-SQL in 2005)


Unfortnately, I don't have any samples to share. There is a sample CLR
type that comes with the SQL 2005 beta, but I don't know of the license
terms permit me to repost the code to public newsgroups, and I am not
taking chances.

Anyway, this is very different from Oracle. Before you start type T-SQL,
you will have write the implementation for your type in a .Net language:
C#, Visual Basic or C++.

Once that is done, you enter the assembly into SQL Server with CREATE
ASSEMBLY and then finally you create the type with CREATE TYPE.

Once you have created the type, you can refer to components of the type
with dot notation:

SELECT @cmplxnumber.x = 1

If you have defined methods on the type you can refer to these with
dot notation as well.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #7
Hi Erland.
I guess I was mainly interested in knowing how different these
two features are - and I can see that they are completely different.
Even the SQL to access the code seems to be quite different (From your
one example.)

Many thanx!

Erland Sommarskog wrote:
Unfortnately, I don't have any samples to share. There is a sample CLR type that comes with the SQL 2005 beta, but I don't know of the license terms permit me to repost the code to public newsgroups, and I am not
taking chances.

Anyway, this is very different from Oracle. Before you start type T-SQL, you will have write the implementation for your type in a .Net language: C#, Visual Basic or C++.

Once that is done, you enter the assembly into SQL Server with CREATE
ASSEMBLY and then finally you create the type with CREATE TYPE.

Once you have created the type, you can refer to components of the type with dot notation:

SELECT @cmplxnumber.x = 1

If you have defined methods on the type you can refer to these with
dot notation as well.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp


Jul 23 '05 #8
Menon (rm*******@gmail.com) writes:
Even the SQL to access the code seems to be quite different (From your
one example.)


Huh? You had

self.name := null;

and I had

SELECT @cmplx.x = 1

That is the same as far accessing the components goes. Then it goes
without saying that there are tons of differences between MS SQL Server
and Oracle, and some are reflected in these samples. The @ in my
example signifies that this is a variable and not a column.

If you really want to make any useful comparison specific features, you
first need to learn some basics about T-SQL, before going into the gory
details.

I don't know PL/SQL or Oracle in general, but judging from your example,
it's quite different from T-SQL. As a programming language it also
appears to be a lot cleaner. T-SQL has some quite syntax details in
some places.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.