Anda di halaman 1dari 4

CSC 182 Lecture Notes

1. The SQL CREATE TABLE command is used for the initial definition of database
table.

Sample

CREATE TABLE MEMBERS (

INIT CHAR(3),
SURNAME CHAR(20),
TELEPHONE_NO INTEGER,
TYPE CHAR(10)
);

2. ALTER TABLE maybe used for changing column definitions using the MODIFY
clause. Columns and table constraints maybe added using the ADD clause.

Sample

ALTER TABLE MEMBERS


MODIFY (TELEPHONE_NO CHAR(12) );

Sample

ALTER TABLE MEMBERS


ADD (NO INTEGER );

If u want NO to be the primary key then execute this SQL command:

ALTER TABLE MEMBERS


MODIFY (NO NOT NULL PRIMARY KEY);

Note: the above command be executed in one SQL command

CREATE TABLE MEMBERS (

NO INTEGER NOT NULL PRIMARY KEY,


INIT CHAR(3),
SURNAME CHAR(20),
TELEPHONE_NO INTEGER,
TYPE CHAR(10)
);

3. Rows values are created thru SQL INSERT

Sample

INSERT INTO MEMBERS


VALUES (1,’AMS’, ‘MUIN’,2213344,’Novice’);

Note: if u mean to insert in every column then you may not specify the name of each field but
sure to input correct data into the order of each field respectively…dili pwede in any order ang
pag insert sa data…

How about if 3 values lang ang lagyan ko sa table???


Ans: follow this sample:

Sample

INSERT INTO MEMBERS (SURNAME, INIT, TYPE)

VALUES (‘MUIN’, ’AMS’,’Novice’);

4. DROP TABLE is to delete certain table, maybe just to renew all fields or to totally
remove it from database.

Sample

DROP TABLE MEMBERS;

Note : Be sure no data were inserted else you cant drop it.

5. Retrieving data from a table

Sample
If u want all fields of a table be display then use asterisk.
Note : Members is just an example of table name. So depende sa table name na gamitin nyo
ha?

Select * from Members;


*********
If not all fields then just specify .
Select NO, Surname from Members;

NO SURNAME

1 Singson
2 Ang
3 Erap

**********
If you have some condition like searching for profile of a members using his ID #.

Select Surname
From Members
Where NO = 1;

Giving result of

Surname

Singson
*****************
Using Comparison operator

Select Surname
From Members
Where NO>3;

>
<
=
<>
And
Or
Those operators are useful in your queries.

6. To be continue…

Note: Pls study the above SQL Command. I will be giving you a Hands-ON exam on this. Be sure
you have created your database. We will have a make-UP class on Sunday 1-4 exactly. Hands-
On and rechecking on what I have told you to modify in your interface.

I am giving you until Last Week of November to finish you SOFTWARE and file for a defense, after
that I can give you a failing grade. Sometimes people needs to be pressured in order to work
harder.
//mia ang database daw sa inyo system ang e hands-on. Hehehehehehehe…

Anda mungkin juga menyukai