Create a Freight Calculation Table in sql server 2012

Asked

Viewed 193 times

1

I have the following question and I need the help of the experts in order to continue my project. I need to create an equal freight table from the image below, only I don’t know if I create a single table or create several tables, because then I have to make a Join with my order table to calculate freight.

follows the table image I need to create in sql, this table has value by weight, state and city(if and capital or interior) inserir a descrição da imagem aqui

follows the way I created the tables, now I came up with a doubt, as I will treat the weight calculation with and structure of tables below that I created, I created a table of state, a table of tariffs to verify if and capital or interior, and the price chart and how now to check the weight also this and my doubt. next thank you.

CREATE TABLE Estados
(
  Id INT,
  Sigla VARCHAR(2),
  CONSTRAINT PK_Estados PRIMARY KEY (Id, Sigla)
)

CREATE TABLE Tarifas
(
  Id INT PRIMARY KEY IDENTITY(1,1),
  Descricao VARCHAR(20)
)

CREATE TABLE TabelaPreco
(
  Id INT PRIMARY KEY IDENTITY(1,1),
  IdEstado INT,
  IdTarifa INT,
  Preco1 decimal default 0, --Faixa 5
  Preco2 decimal default 0, --Faixa 10
  Preco3 decimal default 0, --Faixa 15
  Preco4 decimal default 0, --Faixa 20
  Preco5 decimal default 0, --Faixa 30
  Preco6 decimal default 0, --Faixa 50
  Preco7 decimal default 0, --Faixa 75
  Preco8 decimal default 0, --Faixa 100
  PrecoAdicionalKG decimal default 0 --Preco Adional KG
)

1 answer

1


--without sticking to Pks and Fks

CREATE TABLE Estados
(
  Id INT,
  Sigla VARCHAR(2),
  CONSTRAINT PK_Estados PRIMARY KEY (Id, Sigla)
)

CREATE TABLE Tarifas
(
  Id INT PRIMARY KEY IDENTITY(1,1),
  Descricao VARCHAR(20)
)

CREATE TABLE Faixas
(
  Id INT PRIMARY KEY IDENTITY(1,1),
  Descricao VARCHAR(20)
)

CREATE TABLE TabelaPreco
(
  Id INT PRIMARY KEY IDENTITY(1,1),
  IdEstado INT,
  IdTarifa INT,
  IdFaixa INT,
  VigenciaDe DATE,
  VigenciaAte DATE,
  Preco  decimal default 0
  PrecoAdicionalKG decimal default 0 --Preco Adional KG
)

I believe that it is also necessary to define where the information "destination" is , she changes the value of freight ?

  • Motta good morning, just a doubt, on the track table and to put the correct weight, if and 5, 10, 20...etc and so on?

  • Yes, because the rule will change , something like a track of "150" appears, the application would have to be changed , so just create a record.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.