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

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

The document summarizes the key SQL commands used for creating, modifying, querying, destroying, and altering relational database tables. It covers commands for creating tables, inserting and deleting tuples, updating records, selecting data with queries, adding and dropping attributes, and defining primary keys, foreign keys, and relationships between tables.

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 views3 pages

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

The document summarizes the key SQL commands used for creating, modifying, querying, destroying, and altering relational database tables. It covers commands for creating tables, inserting and deleting tuples, updating records, selecting data with queries, adding and dropping attributes, and defining primary keys, foreign keys, and relationships between tables.

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/ 3

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