DB2 SQL BASIC — 1

CREATE TABLE

CREATE TABLE STUDENT    
(STUDENTID NUMERIC NOT NULL,
CLASS VARCHAR(36) NOT NULL,
TEACHERID NUMERIC ,
LOCATION CHAR(16) ,
PRIMARY KEY(STUDENTID) )
CREATE TABLE NEW_PROJECT LIKE PROJECT;
CREATE TABLE EMP_WITH_DEPT AS
(SELECT EMPNO, FIRSTNME, LASTNAME, PHONENO,
SALARY+COMM+BONUS AS TOTAL_COMP,
FROM EMP E, DEPT D WHERE E.WORKDEPT = D.DEPTNO)
WITH DATA/WITH NO DATA;

Short and Long Column name

CREATE TABLE TABLE_NAME( COLUMN_LONG_NAME For Column COLUMN_SHORT_NAME COLUMN_DATA_TYPE )
CREATE TABLE CUSTOMER( Customer_Name For Column CusName CHAR(10) )

ALTER TABLE

ALTER TABLE STUDENT ADD COLUMN CITY CHAR(10)
ALTER TABLE DEPT DROP COLUMN NUMDEPT
ALTER TABLE EX1 ALTER COLUMN COL2 SET DATA TYPE VARCHAR(30)
ALTER TABLE STUDENT
ALTER COLUMN CITY SET DATA TYPE VARCHAR(100)
ADD COLUMN STATE CHAR(2)
DROP COLUMN OLD_CITY ;

DROP TABLE

DROP TABLE <table_name>
DROP TABLE DEPARTMENT

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store