关系数据库

1. 建表

1 create table student(
2     sno char(8),
3     sname char(8),
4     sbirth date,
5     ssex char(2),
6     sdept char(30)
7 );

2. 删表

1 drop table student1;

3.  常见数据类型

4. 声明主码

1 create table student(
2     sno char(8) primary key,
3     sname char(8),
4     sbirth date,
5     ssex char(2),
6     sdept char(30)
7 );

5. 声明外码

1 create table course (
2     cno char(8) primary key,
3     cname char(30),
4     cpno char(8) references course(cno),
5     credit smallint
6 );

6. 声明主码,外码的另一种方式

1 create table sc (
2     sno char(8),
3     cno char(8),
4     grade smallint,
5     primary key(sno,cno),
6     foreign key(sno) references student(sno),
7     foreign key(cno) references course(cno)
8 );
原文地址:https://www.cnblogs.com/coderJiebao/p/Database01.html