帮帮我解决问题? PLS [英] Help me problem my script ? pls

查看:126
本文介绍了帮帮我解决问题? PLS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我的脚本似乎有点错误。你能修好我的剧本吗?



这里有一张图片:



http://s1042.photobucket。 com / user / dao1001 / media / 1_zpsmkfzy4p1.png.html



这是一个创建5个表,其中包含正确的属性和约束。



http://s1042.photobucket.com/user/dao1001/media/3_zpsobbnpbnm.jpg.html



然后还之后我还有更多东西...



谢谢



我尝试过的:



I have a problem my script seem to error a bit. Could you fix my script ?

here one pic:

http://s1042.photobucket.com/user/dao1001/media/1_zpsmkfzy4p1.png.html

and this is a create 5 tables with the right attributes and constraints here.

http://s1042.photobucket.com/user/dao1001/media/3_zpsobbnpbnm.jpg.html

and then also I have more thing there after that...

Thanks

What I have tried:

/* to create an employee table */

CREATE TABLE employee
(
	EmpId		char(2)		PRIMARY KEY,
	FirstName	varchar(20)	NOT NULL,
	LastName	varchar(20)	NOT NULL,
	Gender		char(2)		CHECK(gender IN ('M', 'F')),
	DateJoined	date		NOT NULL,
	DateLeft	date,
	Contract	varchar(4)	NOT NULL);

/* to create task table */

CREATE TABLE task
(
	TaskId		char(4)		PRIMARY KEY,
	TaskName	varchar(25)	NOT NULL,
	GivenDate	date		NOT NULL,
	StartDate	date,
	EndDate		date,
	MaxHours	number(3,1)	DEFAULT 20.0 NOT NULL);

/* to create computer table */

CREATE TABLE computer
(
	SerialNum	char(7)		PRIMARY KEY,
	Make		varchar(12)	NOT NULL,
	Model		varchar(20)	NOT NULL,
	ProcessorType	varchar(20)	NOT NULL,
	ProcessorSpeed	number(4,2)	NOT NULL,
	RAM		char(7),
	DiskSize	char(6));

/* to create job table */

CREATE TABLE job

(
	TaskId		char(4)		PRIMARY KEY, FOREIGN KEY,
	EmpId		char(2)		PRIMARY KEY, FOREIGN KEY,
	HoursSpent	number(3,1)	DEFAULT 20.0 NOT NULL);

/* to create employee computer table */

CREATE TABLE emp_computer
(
	SerialNum	char(7)		PRIMARY KEY, FOREIGN KEY,
	EmpId		char(2)		PRIMARY KEY, FOREIGN KEY,
	DateAssigned	date		NOT NULL,
	Notes		varchar(50));

推荐答案

假设您使用的是SQL Server。您的脚本中存在许多问题。

1)数据类型为 numeric(x,y)不是数字(x,y)

2)您只能指定一次PRIMARY KEY约束。如果需要复合主键,请不要使用内联定义。

3)您的外键需要指定目标表和列。

4)使用命名约束,它以后会为你节省很多麻烦。



以下是它的样子:

Assuming you are using SQL Server. There are number of problems in your script.
1) The data type is numeric(x,y) not number(x,y)
2) You can only specify PRIMARY KEY constraint once. Do not use the inline definition if you need compound primary key.
3) Your foreign keys need to specify the target table and column.
4) Use named constraints, it will save you lots of trouble later.

Here is how it should look like:
CREATE TABLE job
(
	TaskId		char(4) NOT NULL,
	EmpId		char(2) NOT NULL,
	HoursSpent	numeric(3,1) NOT NULL CONSTRAINT DF_job_HoursSpent DEFAULT (20.0),

	CONSTRAINT PK_job PRIMARY KEY (TaskId, EmpId),
	CONSTRAINT FK_job_task FOREIGN KEY (TaskId) REFERENCES task (TaskId),
	CONSTRAINT FK_job_empoyee FOREIGN KEY (EmpId) REFERENCES employee (EmpId)
);


这篇关于帮帮我解决问题? PLS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆