DB2 SQL BASIC — 1

  1. Data Control Language (DCL) statements: To handle data security. For example, GRANT and REVOKE statements.
  2. Data Definition Language (DDL) statements: To work with SQL objects like Database, Table, Index, etc. CREATE, DROP and ALTER these kinds of statements come under this category.
  3. Data Manipulation Language (DML) statements: To access and modify data. SELECT, INSERT, DELETE, and UPDATE come under this category.

CREATE TABLE

  1. Basic 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 )
  • “FOR” or “For COLUMN” give the option to define a short name for the column
CREATE TABLE CUSTOMER( Customer_Name For Column CusName CHAR(10) )

ALTER TABLE

  1. The altered table may consist of up to 8000 columns.
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

--

--

--

A programmer.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Copy directories and files to and from Kubernetes Container [POD]

How to simplify your DNS management in a hybrid Cloud environment

Qualcomm Interview Experience for FTE (On-Campus: BITS Pilani)

TDD, BDD in Javascript World. Node. Refactoring and notes. 5/5

Top reasons to build an app based on microservices in Node.js

Nano syntext highligh

Building Credible Software

A brief description of Kafka replication mechanism

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
Sumit goyal

Sumit goyal

A programmer.

More from Medium

History of SQL

SQL — How your CS degree only scratches the surface

SELECT statement for SQL

SELECT statement for SQL