Python-day11-mysql Database and Data sheet

Source: Internet
Author: User

Creative Library
Create DATABASE lianx1 DEFAULT Character Set UTF8


Table ################################
int, data type, representing integer
Not NULL means cannot be empty
Auto_increment indicates that the self-increment
PRIMARY key denotes primary key
Constraint foreign Key Name foreign key (the column to be associated) references the associated table (the associated column);

Create a class table
CREATE TABLE Class (
CID int NOT NULL auto_increment PRIMARY key,
Caption Char (32));


Create student Tables
CREATE TABLE Student (
Sid int NOT NULL auto_increment PRIMARY key,
Sname Char (32),
Gender char (32),
class_id int NOT NULL,
Constraint stu1 foreign KEY (class_id) references Class (CID));


Create a teacher table
CREATE TABLE Teacher (
TID int not NULL auto_increment PRIMARY KEY,
Tname Char (32));

Create a curriculum
CREATE TABLE Course (
CID int NOT NULL auto_increment PRIMARY KEY,
CNAME char (32),
tearch_id int NOT NULL,
Constraint Cour1 foreign KEY (tearch_id) References teacher (TID));


Create a score table
CREATE TABLE Score (
Sid int NOT NULL auto_increment PRIMARY KEY,
student_id int,
corse_id int,
Number char (32),
Constraint Score1 foreign KEY (student_id) references student (SID),
Constraint Score2 foreign KEY (corse_id) References course (CID));

Python-day11-mysql Database and Data sheet

Related Article

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.