Home > database >  SQL data structure
SQL data structure

Time:09-21

Daniel, river's lake emergency, online

CodePudding user response:

 
- orders table
The CREATE TABLE Orderheader (
Orderlid BIGINT,
OrderItemid BIGINT,
Orderid NVARCHAR (200) NOT NULL,
Create_dttime DATETIME DEFAULT CURRENT_TIMESTAMP.
Update_dttime DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP

)
GO

The ALTER TABLE Orderheader ADD CONSTRAINT PK_orderheader_pid PRIMARY KEY (orderlid);
The ALTER TABLE Orderheader ADD CONSTRAINT UK_orderheader_orderid UNIQUE (orderid);
GO


The CREATE TABLE OrderItem (
Orderdetailid BIGINT PRIMARY KEY,
Orderlid BIGINT,
Productid NVARCHAR (100) NOT NULL,
DEFAULT UOM NVARCHAR (10) 'a',
Quantity DECIMAL (10, 2)

)
GO

The ALTER TABLE OrderItem ADD CONSTRAINT FK_orderdetail_headerid
FOREIGN KEY (orderlid) REFERENCES Orderheader (orderlid);


Basic is like this, you can try
  • Related