DDL and DML Commands

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 3

SQL commands list:

Langua
Command List
ge
 CREATE
 DROP
DDL  ALTER
 RENAME
 TRUNCATE

 SELECT
 INSERT
DML
 UPDATE
 DELETE

 GRANT
DCL
 REVOKE

 START TRANSACTION
TCL  COMMIT
 ROLLBACK

DDL:
CREATE DATABASE explainjava;

CREATE TABLE user (


id INT(16) PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(255) NOT NULL
);

DROP DATABASE explainjava;


DROP TABLE user;
ALTER TABLE user ADD COLUMN lastname VARCHAR(255)
NOT NULL;
RENAME TABLE user TO student;
TRUNCATE student;
DML:
SELECT * FROM student;
INSERT INTO student (name, lastname) VALUES
('Dmytro', 'Shvechikov');
INSERT INTO student values(&name,&lastname);
/
UPDATE student SET name = 'Dima' WHERE lastname =
'Shvechikov';
DELETE FROM student WHERE name = 'Dima';

DCL:
CREATE USER 'dmytro'@'localhost' IDENTIFIED BY '123';

GRANT ALL PRIVILEGES ON explainjava.* TO


'dmytro'@'localhost';
FLUSH PRIVILEGES;
REVOKE ALL PRIVILEGES ON explainjava.* FROM
'dmytro'@'localhost';
FLUSH PRIVILEGES;

TCL:
START TRANSACTION;

START TRANSACTION;
INSERT INTO student (name, lastname) VALUES ('Dmytro',
'Shvechikov');
COMMIT;

START TRANSACTION;
INSERT INTO student (name, lastname) VALUES ('Dmytro',
'Shvechikov');
ROLLBACK;

You might also like