Hard sql

T-SQL IDENTITY & FK #9

Problem

SQL Server: T-SQL IDENTITY & FK #9. Write T-SQL against the sample schema.

Hints
  • Use TOP instead of LIMIT
  • ROW_NUMBER() OVER (...)

Your solution

TestStatusDetails
Ready — edit the code above and click Run or Submit.

Solution

CREATE TABLE Orders (
  Id INT IDENTITY(1,1) PRIMARY KEY,
  CustomerId INT NOT NULL,
  Amount DECIMAL(12,2) NOT NULL,
  CreatedAt DATETIME2 DEFAULT SYSUTCDATETIME(),
  CONSTRAINT FK_Orders_Customer FOREIGN KEY (CustomerId) REFERENCES Customers(Id)
);

Try solving on your own first, then reveal the official answer.

Explanation

T-SQL: TOP, IDENTITY, DATETIME2, CREATE OR ALTER, window functions — common in .NET/SQL Server interviews.

Discussion

0

Sign in to join the discussion.

No discussions yet — ask the first question!

Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details