Sergio Tapia
Sergio Tapia

Reputation: 41208

How can I create a table like this in Microsoft SQL?

alt text

Here's what I have so far:

create table rubro (
  id_rubro int primary key,
  nombre_rubro nvarchar(150)
)
go

create table cliente (
  id_cliente int primary key,
  direccion nvarchar(400),
  telefono int,
  nit int
)

Upvotes: 0

Views: 136

Answers (2)

marc_s
marc_s

Reputation: 755157

You just need to create the missing two tables and link them to the cliente table:

create table natural (
  id_cliente int primary key,
  nombre nvarchar(50),
  app nvarchar(50),
  apm nvarchar(50),
  ....
)

alter table dbo.natural
  add constraint fk_natural_cliente
      foreign key(id_cliente) references dbo.cliente(id_cliente)

and the same for the juridico table, too.

In SQL Server, those are just three regular tables, linked by foreign key constraints. Using an OR mapper such as Entity Framework gives you the ability to map those as descendant classes in your .NET domain model - but on the database level, those are just three regular tables - nothing "magic" about them...

Upvotes: 2

Anders Abel
Anders Abel

Reputation: 69280

If I understand the diagram correctly it is a object oriented diagram and not a relational diagram. natural and juridico are subclasses of the superclass cliente.

There is no such concept as inheritance in relational databases. When mapping a clas hierarchy there are a few common patterns to use:

All of them have their separate pros and cons. I would suggest you start to read up on those.

Upvotes: 1

Related Questions