1
-- Database: `company`
--
-- --------------------------------------------------------
--
-- Table structure for table `department`
--
CREATE TABLE `department` (
`dname` varchar(45) NOT NULL,
`dnumber` int(11) NOT NULL,
`mgr_ssn` int(11) NOT NULL,
`mgr_start_date` date NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- --------------------------------------------------------
--
-- Table structure for table `dependent`
--
CREATE TABLE `dependent` (
`essn` int(11) NOT NULL,
`dependent_name` varchar(45) NOT NULL,
`sex` varchar(45) NOT NULL,
`bdate` date NOT NULL,
`relationship` varchar(45) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- --------------------------------------------------------
--
-- Table structure for table `dept_locations`
--
CREATE TABLE `dept_locations` (
`dnumber` int(11) NOT NULL,
`dlocation` varchar(45) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- --------------------------------------------------------
--
-- Table structure for table `employee`
--
CREATE TABLE `employee` (
`fname` varchar(45) NOT NULL,
`minit` varchar(45) NOT NULL,
`lname` varchar(45) NOT NULL,
`ssn` int(11) NOT NULL,
`bdate` date NOT NULL,
`address` varchar(45) NOT NULL,
`sex` varchar(45) NOT NULL,
`salary` int(11) NOT NULL,
`super_ssn` int(11) NOT NULL,
`dno` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- --------------------------------------------------------
--
-- Table structure for table `project`
--
CREATE TABLE `project` (
`pname` varchar(45) NOT NULL,
`pnumber` int(11) NOT NULL,
`plocation` varchar(45) NOT NULL,
`dnum` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- --------------------------------------------------------
--
-- Table structure for table `works_on`
--
CREATE TABLE `works_on` (
`essn` int(11) NOT NULL,
`pno` int(11) NOT NULL,
`hours` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Indexes for dumped tables
--
--
-- Indexes for table `department`
--
ALTER TABLE `department`
ADD PRIMARY KEY (`dnumber`),
ADD KEY `mgr_ssn` (`mgr_ssn`);
--
-- Indexes for table `dependent`
--
ALTER TABLE `dependent`
ADD PRIMARY KEY (`essn`,`dependent_name`);
--
-- Indexes for table `dept_locations`
--
ALTER TABLE `dept_locations`
ADD PRIMARY KEY (`dnumber`,`dlocation`);
--
-- Indexes for table `employee`
--
ALTER TABLE `employee`
ADD PRIMARY KEY (`ssn`),
ADD KEY `super_ssn` (`super_ssn`);
--
-- Indexes for table `project`
--
ALTER TABLE `project`
ADD PRIMARY KEY (`pnumber`),
ADD KEY `dnum` (`dnum`);
--
-- Indexes for table `works_on`
--
ALTER TABLE `works_on`
ADD PRIMARY KEY (`essn`,`pno`),
ADD KEY `pno` (`pno`);
--
-- Constraints for dumped tables
--
--
-- Constraints for table `department`
--
ALTER TABLE `department`
ADD CONSTRAINT `mgr_ssn` FOREIGN KEY (`mgr_ssn`) REFERENCES
`employee` (`ssn`) ON DELETE NO ACTION ON UPDATE NO ACTION;
--
-- Constraints for table `dependent`
--
ALTER TABLE `dependent`
ADD CONSTRAINT `fk_essn` FOREIGN KEY (`essn`) REFERENCES `employee`
(`ssn`) ON DELETE NO ACTION ON UPDATE NO ACTION;
--
-- Constraints for table `dept_locations`
--
ALTER TABLE `dept_locations`
ADD CONSTRAINT `dnumber` FOREIGN KEY (`dnumber`) REFERENCES
`department` (`dnumber`) ON DELETE NO ACTION ON UPDATE NO
ACTION;
--
-- Constraints for table `employee`
--
ALTER TABLE `employee`
ADD CONSTRAINT `super_ssn` FOREIGN KEY (`super_ssn`) REFERENCES
`employee` (`ssn`) ON DELETE NO ACTION ON UPDATE NO ACTION;
--
-- Constraints for table `project`
--
ALTER TABLE `project`
ADD CONSTRAINT `dnum` FOREIGN KEY (`dnum`) REFERENCES `department`
(`dnumber`) ON DELETE NO ACTION ON UPDATE NO ACTION;
--
-- Constraints for table `works_on`
--
ALTER TABLE `works_on`
ADD CONSTRAINT `essn` FOREIGN KEY (`essn`) REFERENCES `employee`
(`ssn`) ON DELETE NO ACTION ON UPDATE NO ACTION,
ADD CONSTRAINT `pno` FOREIGN KEY (`pno`) REFERENCES `project`
(`pnumber`) ON DELETE NO ACTION ON UPDATE NO ACTION;
COMMIT;
########################################################
Give a ThumbsUp if you found this answer Helpful :)
#######################################################
In the Case of multiple questions,we(Experts) should answer only
certain number of sub-parts\questions.So kindly ask the remaining
sub-parts\questions as a new query. Sorry for the inconvenience
caused.
################################################################
............ Still having trouble understanding the answer ? Feel
free to ask in the comment section.......
Task for today: 1. Create all the tables for Database company. Focus to the PK and...