2015/4/2 SQL database to create a Table table association

Source: Internet
Author: User

1. Create a "student" table Student

CREATE TABLE Student_muanfeng (

Sno Char (4) primary key (primary key),

Sname char unique (for constraint),

Ssex char (2) null check (Sex in (' M ', ' F ')),

Sage smallint null check (AGE>18 and age<25),

Sdept Char (20)

);

2. Create a "course" table course

Create Table Course (

Cno char (4) Primary key,

Cname Char (40),

Credit smallint null check (credit>0 and credit<10)

);

)

3, set up students ' timetable SC

Create Table SC

Sno Char (4) is not NULL, CNO char (4) is not NULL primary key (SNO,CNO),
Grade smallint null check (grade>0 and grade <100))
ALTER TABLE SC add constraint Fk_sno foreign key (SNO) references Student (SNO);
ALTER TABLE SC add constraint fk_cno foreign key (CNO) references Course (CNO);

2.Create Table SC (

Sno char (4),

Cno Char (4),

Primary Key (SNO,CNO),

Frimary key (Sno) reference student (Sno),

Frimary key (Cno) reference Course (Cno),

);

Insert data:

Insert into table name (condition) value (corresponding value)

2015/4/2 SQL database to create a Table table association

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.