생활코딩

Coding Everybody

코스 전체목록

닫기

많아지는 테이블

수업소개

여기서는 author 테이블을 생성하고, topic 테이블을 변경해서 author 테이블을 참조하도록 하는 방법을 살펴봅니다. 

 

강의

 

소스코드(SQL)

아래 소스코드는 실습에 사용할 테이블을 생성하는 SQL문입니다. 기존에 존재하는 테이블을 삭제하고 새로 테이블을 생성하기 때문에 주의해주세요.

--
-- Table structure for table `author`
--

DROP TABLE IF EXISTS `author`;
CREATE TABLE `author` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(30) NOT NULL,
  `profile` varchar(200) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

--
-- Dumping data for table `author`
--

LOCK TABLES `author` WRITE;
/*!40000 ALTER TABLE `author` DISABLE KEYS */;
INSERT INTO `author` (`id`, `name`, `profile`) VALUES (1,'egoing','developer'),(2,'duru','DBA'),(3,'taeho','Data scientist');
/*!40000 ALTER TABLE `author` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `topic`
--

DROP TABLE IF EXISTS `topic`;
CREATE TABLE `topic` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(45) NOT NULL,
  `description` text,
  `created` datetime NOT NULL,
  `author_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=36 DEFAULT CHARSET=utf8;

--
-- Dumping data for table `topic`
--

LOCK TABLES `topic` WRITE;
INSERT INTO `topic` (`id`, `title`, `description`, `created`, `author_id`) VALUES (19,'MySQL ','MySQL is ...','2018-02-20 11:35:32',1),(20,'Oracle','Oracle is ...','2018-02-20 11:35:39',1),(21,'SQL Server','SQL Server is ...','2018-02-20 11:35:50',2),(22,'MongoDB','MongoDB is ..','2018-02-20 11:35:59',3),(34,'MariaDB ','MariaDB is ...','2018-02-22 11:49:09',1),(35,'OrientDB','OrientDB is ..','2018-02-22 12:13:12',1);
UNLOCK TABLES;

--
-- Table structure for table `user`
--

DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
  `email` varchar(30) NOT NULL,
  `password` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Dumping data for table `user`
--

LOCK TABLES `user` WRITE;
INSERT INTO `user` (`email`, `password`) VALUES ('asdf@o2.org','222222'),('qwer@o2.org','111111'),('zxcv@o2.org','333333');
UNLOCK TABLES;

 

댓글

댓글 본문
버전 관리
egoing
현재 버전
선택 버전
graphittie 자세히 보기