Docsity

cheatsheet comandi base sql, Schemi e mappe concettuali di Programmazione Avanzata

Anteprima parziale del testo

Scarica cheatsheet comandi base sql e più Schemi e mappe concettuali in PDF di Programmazione Avanzata solo su Docsity!

05/10/24, 14:09 ‘about:blank SQL Cheat Sheet: CREATE TABLE, ALTER, DROP, TRUNCATE Command CREATE TABLE ALTER TABLE - ADD COLUMN ALTER TABLE - ALTER COLUMN ALTER TABLE - DROP COLUMN ALTER TABLE - RENAME COLUMN TRUNCATE TABLE DROP TABLE Author(s) Hi Bi Syntax MySQL/DB2: CREATE TABLE table_name (coli datatype optional keyword, col2 datatype optional keyword,col3 datatype optional Reyword,..., coln datatype optional Reymord) MySQL/DB2: Option 1. ALTER TABLE table_name ADD column_name_1 datatype. . . .ADD COLUMN column_name_n datatype; Option 2. ALTER TABLE table_name ADD COLUMN column_name_1 datatype. . ..ADD COLUMN column_name_n datatype; MySQL: ALTER TABLE table_name MODIFY column_name_1 new data_type; DB2: ALTER TABLE table_name ALTER COLUMN column_name_1 SET DATA TYPE datatype; MySQL/DB2: ALTER TABLE table_name DROP COLUMN column name_1 ; MySQL:ALTER TABLE table_name CHANGE COLUMN current_column_name new_column_name datatype [optional keywords]; DB2: ALTER TABLE table_name RENAME COLUMN current_column_name TO new_column_name; MySQL: TRUNCATE TABLE table_name; DB2: TRUNCATE TABLE table_name IMMEDIATE; MySQL/DB20ROP TABLE table_name ; Niveditha Pandith TS about:blank Description CREATE TABLE statement is to create the table. Each column in the table is specified with its name, data type and an optional keyword which could be PRIMARY KEY, NOT NULL, etc., ALTER TABLE statement is used to add the columns to a table. MySQL: ALTER TABLE MODIFY MODIFY clause is used with the ALTER TABLE statement to modify the data type of columns. Db2: ALTER TABLE ALTER COLUMN statement is used to modify the data type of columns. ALTER TABLE DROP COLUMN statement is used to remove columns from a table. MySQL: ALTER TABLE CHANGE COLUMN CHANGE Example MySQL/DB2: CREATE TABLE employee ( employee_id char(2) PRIMARY KEY, first_name varchar(30) NOT NULL, mobile int); MySQL/DB2 Option 1. ALTER TABLE employee ADD income bigint; Option 2. ALTER TABLE employee ADD COLUMN income bigint; MySQL: ALTER TABLE employee MODIFY mobile CHAR(20); DB2: ALTER TABLE employee ALTER COLUMN mobile SET DATA TYPE CHAR(20); MySQL/DB2: ALTER TABLE employee DROP COLUMN mobile ; COLUMN clause is used to rename the columns MYSQL: ALTER TABLE employee CHANGE COLUMN in a table. DB2: ALTER TABLE RENAME COLUMN statement is ‘used to rename the columns in a table. MySQL: TRUNCATE TABLE statement is used to delete all of'the rows in a table. Db2: The IMMEDTATE specifies to process the statement immediately and that it cannot be ‘undone. Use the DROP TABLE statement to delete a table from a database. If you delete a table that contains data, by default the data will be deleted alongside the table. first_name name VARCHAR(255); DB2: ALTER TABLE employee RENAME COLUMN finst_name TO name; MySQL: TRUNCATE TABLE enployee; DB2: TRUNCATE TABLE employee IMMEDIATE ; MySQU/DB2: DROP TABLE employee ; ills Network 1/1