1

コンピュータ インベントリ用のデータベースを作成しました。私の課題は、「Dell」や「IBM」などの特定の単語のみをフィールドに入力できるようにすることです。テーブルの作成方法は次のとおりです。

Create table computer_inventory ( 
 assetnumber int(10) not null default 0,
 manufacturer char(3) ENUM('Dell', 'IBM', 'OtherCompany') NOT NULL default ' ', 
 originalcost decimal(12,2) not null default 0, 
 currentvalue decimal(12,2) not null default 0, 
 boughtfrom varchar(20) not null default ' ', 
 instock tinyint(1) not null default 0, 
 currentuser varchar(20) not null default ' ',
 userphonenum varchar(13) not null default ' ',
 boughtdate datetime not null default '0000-00-00'
);

今度は、製造元として「DELL」または「IBM」のみを入力できるようにすることを想定しています。

4

2 に答える 2

1

コードに 2 つのエラーがあります。

  1. 3 行目は許可されていません: char(3)より多くの文字 ( dell - 4 文字) で値を宣言したためです。
  2. 3 行目は許可されていません:デフォルト ' ' - 宣言された値のリストに ' ' がないためです。リスト ENUM('Dell', 'IBM', 'OtherCompany') の値のみを指定できます

正しいコード:

Create table computer_inventory ( 
assetnumber int(10) not null default 0,
manufacturer ENUM('Dell', 'IBM', 'OtherCompany') NOT NULL, 
originalcost decimal(12,2) not null default 0, 
currentvalue decimal(12,2) not null default 0, 
boughtfrom varchar(20) not null default ' ', 
instock tinyint(1) not null default 0, 
currentuser varchar(20) not null default ' ',
userphonenum varchar(13) not null default ' ',
boughtdate datetime not null default '0000-00-00')
于 2016-05-23T14:24:21.333 に答える