0% found this document useful (0 votes)
25 views2 pages

Ej: CREATE TABLE Enrolled (sID Char (20), cID Char (20), Grade Char (2) NOT NULL)

The document describes the SQL language and its basic commands for creating, modifying, querying, updating, destroying, and altering database relations. It covers commands to create tables, insert tuples, delete tuples, select attributes, update values, drop tables, add attributes, define primary keys, and define foreign keys.

Uploaded by

Darling Silva
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views2 pages

Ej: CREATE TABLE Enrolled (sID Char (20), cID Char (20), Grade Char (2) NOT NULL)

The document describes the SQL language and its basic commands for creating, modifying, querying, updating, destroying, and altering database relations. It covers commands to create tables, insert tuples, delete tuples, select attributes, update values, drop tables, add attributes, define primary keys, and define foreign keys.

Uploaded by

Darling Silva
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

SQL Language

Creation:

CREATE <relation name>(<attributes>);

Ej: CREATE TABLE Enrolled (sID char(20), cID char(20), grade char(2) NOT NULL);

Modification:

Adding tuples

INSERT INTO <relation name>(<attribute names>)

VALUES (<attribute values>);

Ej: INSERT INTO Students (sID, name, user, age,gpa)

VALUES (5400, Pedro Gomez, pgomez, 35, 5.1),(55235, Javier Rios,jrios,28,5.8);

Deleting tuples

DELETE FROM <relation name>

WHERE <condition>

Ej: DELETE FROM Students

WHERE user = fpinto

Querying:

SELECT <attribute names>

FROM <relation names>

WHERE <condition>

Update:

UPDATE <relation name>

SET <new value assignments>

WHERE <condition>;

Ej: UPDATE Students

SET= gpa*1,1,age=age+1

WHERE sID <53670


Destroying:

DROP TABLE <relation name>;

Ej: DROP TABLE Students;

Altering Relations (Adding attributes):

ALTER TABLE <relation name>

ADD <Attribute>;

Ej: ALTER TABLE Students

ADD firstYear INTEGER;

Primary keys and Candidate keys

CREATE TABLE Enrolled


(sID CHAR(20),
cID CHAR(20),
grade CHAR(2),
PRIMARY KEY (sID,cID),
UNIQUE (cid, grade) );

Foreign Keys in SQL


CREATE Enrolled
(sID CHAR(20),
cID CHAR(20),
grade CHAR(2),
PRIMARY KEY (sID,cID)
FOREIGN KEY (sID) REFERENCES Students,
FOREIGN KEY (cID) REFERENCES Courses);

You might also like