Create Table if not Exists sc - SQL 语法详解
SQL Create Table if not Exists sc 语法详解
本篇详细解析 SQL 语句 'create table if not exists sc',该语句用于创建名为 'sc' 的数据表(如果该表不存在)。
语句示例:
create table if not exists sc (
sno char(10),
cno char(10),
grade smallint,
primary key (sno, cno),
foreign key(sno) references student (sno),
foreign key(cno) references course (cno)
);
语句解析:
create table if not exists sc: 如果名为 'sc' 的表不存在则创建该表。sno char(10): 定义名为 'sno' 的列,数据类型为字符型,最大长度为 10 个字符。cno char(10): 定义名为 'cno' 的列,数据类型为字符型,最大长度为 10 个字符。grade smallint: 定义名为 'grade' 的列,数据类型为小整数型。primary key (sno, cno): 定义 'sno' 和 'cno' 两列共同构成表的主键。foreign key(sno) references student (sno): 定义 'sno' 列为外键, 引用自 'student' 表的 'sno' 列。foreign key(cno) references course (cno): 定义 'cno' 列为外键,引用自 'course' 表的 'cno' 列。
总结:
上述 SQL 语句用于创建名为 'sc' 的表,并定义了表的列名、数据类型、主键和外键关系,确保数据完整性和一致性。
原文地址: https://www.cveoy.top/t/topic/cIIn 著作权归作者所有。请勿转载和采集!