This presentation is the property of its rightful owner.
Sponsored Links
1 / 37

第 6 讲 SQL 语言基础及数据定义功能 PowerPoint PPT Presentation


  • 76 Views
  • Uploaded on
  • Presentation posted in: General

第 6 讲 SQL 语言基础及数据定义功能. www.desktop.swpu.edu.cn. 1. 2. 3. 4. SQL 语言功能概述. 数据定义. SQL 概述. 学生课程数据库简介. 本讲内容. 6.1 SQL 概述. SQL ( Structured Query Language ) 结构化查询语言,是关系数据库的标准语言. SQL 是一个通用的、功能极强的关系数据库语言. 现在所有的关系数据库管理系统都支持 SQL ,就连个人计算机上使用的数据库也不例外。. 2. 3. 1. SQL 语言特点.

Download Presentation

第 6 讲 SQL 语言基础及数据定义功能

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


6 sql

6 SQL

www.desktop.swpu.edu.cn


6 sql

1

2

3

4

SQL

SQL


6 1 sql

6.1 SQL

  • SQLStructured Query Language

  • SQL

  • SQL


6 1 sql1

2

3

1

SQL

SQL

SQL

6.1 SQL


6 sql

SQL

SQLIBM70SEQUELStructured English QUEry Language

SQLSQLSQL


6 sql

  • SQL893ISOANSI19928SQLSQL-92SQL2SQL-921999SQLSQL-99SQL3

SQLRDBMSSQL198610ANSIISO1987619894ISOSQLSQL-89


6 sql

SQL

2

1

3

SQL

4

5


6 sql

1

  • DDLDMLDCL


6 sql

2

  • SQL

  • SQL


6 sql

3

  • SQL9


6 sql

4

  • SQL


6 sql

5

  • SQL

  • SQL

  • SQLVisual BasicCC++Java


6 sql

SQL

3

4

2

1


6 sql

1

SQL

1

2

1

2

3

4

2

1

  • SQL


6 sql

2

  • SQL

  • ()


6 sql

3


6 sql

4


6 sql

6.2 -

1

2

3

4

-ST

Student

Course

SC


1 s t

1 - S-T

  • Student(Sno,Sname,Ssex,Sage,Sdept)

  • Course(Cno,Cname,Cpno,Ccredit)

  • SC(Sno,Cno,Grade)


2 student

2Student


3 course

3Course


6 sql

4SC


6 3 sql

6.3 SQL

SQL


6 sql


6 sql

1

2

3

6.4


6 sql

  • Create Table

CREATE TABLE <>

<> <> []

{, <> <> }

[, ]

<>

<>

<>


6 sql


6 sql

  • NOT NULL

  • DEFAULTDEFAULT

  • UNIQUE

  • CHECKCHECK

  • PRIMARY KEY

  • FOREIGN KEY:

  • FOREIGN KEY<> REFERENCES <><>


Not null default

CHECK

1

FOREIGN KEY<><>

NOT NULLDEFAULT


Sql student

StudentSQL

SQLStudent

Student

CREATE TABLE Student (

Sno char ( 7 ) PRIMARY KEY,

Sname char ( 10 ) NOT NULL,

Ssex char (2) CHECK (Ssex = '' OR Ssex = ''),

Sage tinyint CHECK (Sage >= 15 AND Sage <=45),

Sdept char (20 ) DEFAULT '' )


Sql course

course

SQLCourse

CREATE TABLE Course (

Cno char(10) NOT NULL,

Cname char(20) NOT NULL,

Ccredit tinyint CHECK (Ccredit > 0),

Semester tinyint CHECK (Semester > 0),

Period int CHECK (Period > 0),

PRIMARY KEY(Cno) )


Sql sc

SC

SQLSC

CREATE TABLE SC (

Sno char(7) NOT NULL,

Cno char(10) NOT NULL,

Grade tinyint,

CHECK (Grade >= 0 and Grade <= 100),

PRIMARY KEY( Sno, Cno ),

FOREIGN KEY ( Sno ) REFERENCES Student ( Sno ),

FOREIGN KEY ( Cno ) REFERENCES Course ( Cno ) )


6 sql

DROP TABLE <> { [, <> ] }

test:

:

DROP TABLE test


Alter table

ALTER TABLE


6 sql

3ALTER TABLE

ALTER TABLE<>

[ ALTER COLUMN <> <>] --

| [ ADD [COLUMN] <> <> [] --

| [ DROP COLUMN <> ] --

| [ADD PRIMARY KEY [ n ] ] --

| [ADD FOREIGN KEYREFERNECES] --


2 xklb char 6 alter table sc alter column xklb char 6

3CoursePeriod

ALTER TABLE Course

DROP COLUMN Period

2XKLBchar(6)

ALTER TABLE SC

ALTER COLUMN XKLB char(6)


6 sql

Thank You !


  • Login