SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
create table [MsUser]( [UserID] char(5) primary key check([UserID] like 'US[0-9][0-9][0-9]'), [UserName] varchar(100) not null, [UserAddress] varchar(100) not null, [UserGender] varchar(10) not null check([UserGender] in('male', 'female')), [UserPhone] varchar(20) not null check([UserPhone] like '+62%'), [UserEmail] varchar(50) not null ) create table [MsPaymentType]( [PaymentTypeID] char(5) primary key check([PaymentTypeID] like 'PT[0-9][0-9][0-9]'), [PaymentTypeName] varchar(20) not null ) create table [MsProductCategory]( [ProductCategoryID] char(5) primary key check([ProductCategoryID] like 'PC[0-9][0-9][0-9]'), [ProductCategoryName] varchar(100) not null ) create table [MsProduct]( [ProductID] char(5) primary key check([ProductID] like 'PR[0-9][0-9][0-9]'), [ProductCategoryID] char(5) foreign key references [MsProductCategory]([ProductCategoryID]) on update cascade on delete cascade, [ProductName] varchar(100) not null, [ProductPrice] int not null check([ProductPrice] > 0), [ProductStock] int not null ) create table [TransactionHeader]( [TransactionID] char(5) primary key check([TransactionID] like 'TR[0-9][0-9][0-9]'), [UserID] char(5) foreign key references [MsUser]([UserID]) on update cascade on delete cascade, [PaymentTypeID] char(5) foreign key references [MsPaymentType]([PaymentTypeID]) on update cascade on delete cascade, [TransactionDate] date not null ) go create table [TransactionDetail]( [TransactionID] char(5) foreign key references [TransactionHeader]([TransactionID]) on update cascade on delete cascade, [ProductID] char(5) foreign key references [MsProduct]([ProductID]) on update cascade on delete cascade, [Quantity] int not null check([quantity] > 0), primary key([TransactionID], [ProductID]) )
Stuck with a problem? Got Error? Ask ChatGPT!
Copy Clear