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

Swap HDAC to ATOLO using Cosmostation Wallet and HDAC Wallet

What’s new in one.network Version e2.7.0?

Marie Kondo for the Enterprise

A Two Year Journey of orderbird and Datadog — Part II

How To Install Windows Update Cab Files Repair

Data Persistence with Helidon and Native Image

RRC JE (Junior Engineer) (TMC) Post Revised Date of Exam Notice, 2019

RRC JE (Junior Engineer) (TMC) Post Revised Date of Exam Notice, 2019

What is Vinyl & How does it support app development

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

What is SQL?

Using the CASE Statement in SQL Server

What we do before starting a Data Science Project