1 / 22

SQL CREATE, INSERT, UPDATE, DELETE

SQL CREATE, INSERT, UPDATE, DELETE. MUHD EIZAN SHAFIQ BIN ABD AZIZ FSKM, UiTM PAHANG ITS232. ERD. STEPS IN CREATING DB. CREATE NEW DATABASE IN IBM DB2: WIZARD COMMAND LINE PROCESSOR (CLP) SQL:. CREATE DATABASE DB_NAME. STEPS IN CREATING TABLES.

lynley
Download Presentation

SQL CREATE, INSERT, UPDATE, DELETE

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SQLCREATE, INSERT, UPDATE, DELETE MUHD EIZAN SHAFIQ BIN ABD AZIZ FSKM, UiTM PAHANG ITS232

  2. ERD

  3. STEPS IN CREATING DB • CREATE NEW DATABASE IN IBM DB2: • WIZARD • COMMAND LINE PROCESSOR (CLP) • SQL: CREATE DATABASE DB_NAME

  4. STEPS IN CREATING TABLES • CREATE TABLES THAT DO NOT HAVE ANY FKs CREATE TABLE PROGRAMMES ( PROGRAMME_CODE VARCHAR(5) NOT NULL PRIMARY KEY, PROGRAMME_NAME VARCHAR(100) )

  5. STEPS IN CREATING TABLES • CREATE TABLES THAT HAVE FKs CREATE TABLE STUDENTS ( STUDENT_ID VARCHAR(10) NOT NULL PRIMARY KEY, STUDENT_NAME VARCHAR(255) NOT NULL, STUDENT_ICNO VARCHAR(12), PROGRAMME_CODE VARCHAR(5), FOREIGN KEY (PROGRAMME_CODE) REFERENCES PROGRAMMES (PROGRAMME_CODE) )

  6. MODIFYING TABLE STRUCTURE • ADD NEW COLUMN/ATTRIBUTE ALTER TABLE STUDENTS ADD COLUMN STUDENT_GENDER VARCHAR(6);

  7. MODIFYING TABLE STRUCTURE • UPDATE/CHANGE DATATYPE ALTER TABLE STUDENTS ALTER COLUMN STUDENT_GENDER SET DATATYPE VARCHAR(1); ALTER TABLE STUDENTS ALTER COLUMN PROGRAMME_CODE SET NOT NULL;

  8. MODIFYING TABLE STRUCTURE • RENAME COLUMN/ATTRIBUTE NAME ALTER TABLE STUDENTS RENAME COLUMN STUDENT_GENDER TO STUDENTGENDER;

  9. MODIFYING TABLE STRUCTURE • DROP COLUMN/ATTRIBUTE ALTER TABLE STUDENTS DROP COLUMN STUDENTGENDER;

  10. MODIFYING TABLE STRUCTURE • CREATING NEW TABLE CREATE TABLE STATES ( STATE_ID INTEGER NOT NULL, STATE_NAME VARCHAR(50) );

  11. MODIFYING TABLE STRUCTURE • ASSIGNING PK IN A TABLE CREATE TABLE STATES ( STATE_ID INTEGER NOT NULL, STATE_NAME VARCHAR(50) ); ALTER TABLE STATES ADD PRIMARY KEY (STATE_ID);

  12. MODIFYING TABLE STRUCTURE • ASSIGNING NEW FK IN AN EXISTING TABLE ALTER TABLE STUDENTS ADD COLUMN STATE_ID INTEGER; ALTER TABLE STUDENTS ADD FOREIGN KEY (STATE_ID) REFERENCES STATES (STATE_ID);

  13. DROPPING A TABLE • DROPPING ANY TABLES DROP TABLE TABLE_NAME;

  14. REORGANIZE ALL TABLES • AFTER COMPLETELY CREATING YOUR TABLES, PLEASE RUN THIS CODE TO FINALIZE ALL TABLES STRUCTURE REORG TABLE TABLE_NAME;

  15. INSERTING DATA INTO TABLES • INSERT DATA INTO TABLES THAT DO NOT HAVE ANY FKs INSERT INTO PROGRAMMES (PROGRAMME_CODE, PROGRAMME_NAME) VALUES ('CS110', 'DIPLOMA IN COMPUTER SCIENCE'); INSERT INTO PROGRAMMES (PROGRAMME_CODE, PROGRAMME_NAME) VALUES ('AC110', 'DIPLOMA IN ACCOUNTING'); INSERT INTO PROGRAMMES (PROGRAMME_CODE, PROGRAMME_NAME) VALUES ('AT110', 'DIPLOMA IN PLANTATION'); INSERT INTO PROGRAMMES (PROGRAMME_CODE, PROGRAMME_NAME) VALUES ('AS120', 'DIPLOMA IN SCIENCE');

  16. INSERTING DATA INTO TABLES • INSERT DATA INTO TABLES THAT DO NOT HAVE ANY FKs INSERT INTO STATES VALUES (1, 'SELANGOR'); INSERT INTO STATES VALUES (2, 'PAHANG'); INSERT INTO STATES VALUES (3, 'KUALA LUMPUR'); INSERT INTO STATES VALUES (4, 'SELANGOR');

  17. UPDATING EXISTING DATA • UPDATE STATE NAME BELONGS TO STATE_ID = 4 TO KELANTAN UPDATE STATES SET STATE_NAME = 'KELANTAN';

  18. INSERTING DATA INTO OTHER TABLES • INSERT DATA FOR SEVERAL ATTRIBUTES INTO STUDENTS TABLE INSERT INTO STUDENTS (STUDENT_ID, STUDENT_NAME, PROGRAMME_CODE, STATE_ID) VALUES ('2006666002', 'HARUN SALIM BACHIK', 'CS110', 1);

  19. INSERTING DATA INTO OTHER TABLES • INSERT DATA WITHOUT SPECIFYING ATTRIBUTES INSERT INTO STUDENTS VALUES ('2006666003', 'EZZAT AMER BIN AMIRUL AZREEN', '931012145613', 'CS110', 1);

  20. UPDATING DATA FOR MULTIPLE ATTRIBUTES • READ, UNDERSTAND, AND TYPE THE CODE… UPDATE STUDENTS SET STUDENT_NAME = 'ZIZAN RAZAK', STUDENT_IC = '770812095477' WHERE STUDENT_NO = '2006666002';

  21. DELETING DATA FROM TABLE • DELETE DATA BASED ON PK DELETE FROM STATES WHERE STATE_ID = 4;

  22. THE END OF BASIC SQL…

More Related