0

In our Database course in university, our reference book was Fundamentals of Database Systems by Elmasri. In Chapter 12 of this book, we were introduced to Object-Oriented database systems, in which User-Defined Types (UDTs) were treated like objects.

I want to create these UDTs in Microsoft SQL Server 2017, but there seems to be no syntax that correspond to the keywords in the examples of this chapter, such as INSTANTIABLE, FINAL, REF.

I have tried using the syntax CREATE TYPE <type-name> AS ( <definition> ) but it does not seem to work. However, the syntax CREATE TYPE <type-name> AS TABLE ( <definition> ) works in SQL Server Management Studio but I still cannot find equivalents for the keywords mentioned above.

The code (or pseudocode) below is one of the examples provided in the book, and I cannot implement this in SQL Server Management Studio

CREATE TYPE PERSON_TYPE AS (
NAME VARCHAR (35),
SEX CHAR,
BIRTH_DATE DATE,
PHONES USA_PHONE_TYPE ARRAY [4],
ADDR USA_ADDR_TYPE
INSTANTIABLE
NOT FINAL
REF IS SYSTEM GENERATED
INSTANCE METHOD AGE() RETURNS INTEGER;
CREATE INSTANCE METHOD AGE() RETURNS INTEGER
FOR PERSON_TYPE
BEGIN
RETURN /* CODE TO CALCULATE A PERSON’S AGE FROM
TODAY’S DATE AND SELF.BIRTH_DATE */
END;
);
Timisorean
  • 1,388
  • 7
  • 20
  • 30
  • @LukaszSzozda So you are saying that there is no way I can create some UDT in MSQL Server that corresponds to the type above? – Mohammadmahdi Alijani Jul 06 '19 at 12:34
  • 1
    @Yes, SQL Server has limited support for OO types built-in. You could achieve more by using CLR data types(C#). [Creating User-Defined Types](https://learn.microsoft.com/en-us/sql/relational-databases/clr-integration-database-objects-user-defined-types/creating-user-defined-types?view=sql-server-2017) – Lukasz Szozda Jul 06 '19 at 12:37
  • @LukaszSzozda But our instructor said something about that sql server after 2017 supports object oriented database. – Mohammadmahdi Alijani Jul 06 '19 at 12:40
  • Maybe he was referencing external scripts and JAVA support [sp_execute_external_script](https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-execute-external-script-transact-sql?view=sql-server-2017) – Lukasz Szozda Jul 06 '19 at 12:41

0 Answers0