D
D
Denis Kuznetsov2019-12-16 01:15:26
PostgreSQL
Denis Kuznetsov, 2019-12-16 01:15:26

How to change ms sql query to work on postgresql?

Hello, how should I rewrite the query
to ms sql I had

CREATE TABLE dbo.Salary(
Salary_data int NOT NULL,
Salary_date datetime NOT NULL)
GO

ALTER TABLE Salary
ADD CONSTRAINT DF_Salary_Salary_date DEFAULT (getdate()) FOR Salary_date
GO

ALTER TABLE Salary
ADD Employee_ID int NOT NULL
GO

ALTER TABLE Salary
WITH CHECK ADD CONSTRAINT FK_Salary_Employee_ID FOREIGN KEY(Employee_ID)
REFERENCES EMPLOYEE(Employee_ID)
ON UPDATE CASCADE
ON DELETE CASCADE

on postgre I inserted it almost the same way
CREATE TABLE salary
(
  employee_id integer NOT NULL,
  salary_data integer NOT NULL,
  salary_date date NOT NULL
);

ALTER TABLE salary
ADD CONSTRAINT DF_Salary_Salary_date DEFAULT (current_date) FOR salary_date;

ALTER TABLE salary
WITH CHECK ADD CONSTRAINT FK_Salary_Employee_ID FOREIGN KEY(employee_id)
REFERENCES EMPLOYEE(employee_id)
ON UPDATE CASCADE
ON DELETE CASCADE

But he is not satisfied with default and with , please tell me how to change this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey c0re, 2019-12-16
@DennisKingsman

did you try to see how to add default value, constraint, foreign key to the doc?

ALTER TABLE salary ALTER COLUMN salary_date SET DEFAULT current_date;

ALTER TABLE salary
ADD CONSTRAINT FK_Salary_Employee_ID FOREIGN KEY(employee_id)
REFERENCES EMPLOYEE(employee_id)
ON UPDATE CASCADE
ON DELETE CASCADE

The EMPLOYEE table must of course exist, and the employee_id field must be unique.
https://dbfiddle.uk/?rdbms=postgres_10&fiddle=238a...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question