Basic SQL Language

SQL DML and DDL

SQL Language can be divided into two parts: The Data Manipulation Language (DML) and the Data Definition Language (DDL).

The query and update commands form the DML part of SQL:

  • SELECT – extracts data from a database
  • UPDATE – updates data in a database
  • DELETE – deletes data from a database
  • INSERT INTO – inserts new data into a database

The DDL part of SQL permits database tables to be created or deleted. It also define indexes (keys), specify links between tables, and impose constraints between tables. The most important DDL statements in SQL are:

  • CREATE DATABASE – creates a new database
  • ALTER DATABASE – modifies a database
  • CREATE TABLE – creates a new table
  • ALTER TABLE – modifies a table
  • DROP TABLE – deletes a table
  • CREATE INDEX – creates an index (search key)
  • DROP INDEX – deletes an index

Example:

The most important DML syntax in SQL are:

-- SQL Select Syntax
SELECT * from tablename

-- SQL Update Syntax
UPDATE tablename set columnname='value' where rowid=1

-- SQL Delete Syntax
DELETE from tablename where rowid=1

-- SQL Insert into Syntax
INSERT INTO tablename(column1,column2) values('value1','values2')

The most important DDL syntax in SQL are:

-- SQL Create Database Syntax
CREATE DATABASE database_name

-- SQL Create Table Syntax
CREATE TABLE Table1
(
rowid int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
)

-- Alter Table Syntax
ALTER TABLE table1 DROP COLUMN colum1
ALTER TABLE table1 ADD column1 VARCHAR(20) NULL 
-- Drop Table Syntax
Drop TABLE table1
ALTER TABLE table1 DROP INDEX index1
TRUNCATE TABLE table1
-- Create Index Syntax
CREATE UNIQUE INDEX AK_Index ON Table1 (Column1) WITH (IGNORE_DUP_KEY = OFF)

-- Drop Index Syntax
DROP INDEX AK_Index ON Table1