MySQL Learning one: building tables

Source: Internet
Author: User

Goal: Create three tables, Student table student (Sid,name,gender), curriculum Course (cid,name), score mark (Mid, Sid, CID, gender);

Requires SID, Cid, and mid as the primary key,

Student name can only be F or M

The SID CID in Mark is a foreign key, and the combination is unique to ensure that each student can only have one score per course

Start terminal under Ubuntu

Start the MySQL service

sudo service MySQL start

Log in with the root account

Mysql-u root-p

Create a database

Create Database Student_system;

Open Database

Use Student_system;

Create student Tables

CREATE TABLE student (SID Int (primary) key, name Char (a), Gender enum (' F ', ' M '));

Create a curriculum

CREATE TABLE course (CID Int (ten) primary key, name Char (20));

Create a score table

CREATE table mark (mid int (ten) primary key, Sid Int (TEN), Cid Int (ten), score int,

Constraint Mark_sid foreign key (SID) references student (SID),

Constraint mark_cid foreign KEY (CID) References course (CID),

Unique Unique_sid_cid (SID, Cid));

MySQL Learning one: building tables

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.