SQL basics- complete reference guide - part2 - DDL

Part2: DDL -Data Definition Language Reference

CommandDescriptionSYNTAXExample
ALTER INDEX RENAMERenames an index.ALTER INDEX indexName RENAME TO newIndexName
ALTER SCHEMA RENAMERenames a schema.ALTER SCHEMA schema RENAME TO newSchemaName
ALTER SEQUENCEChanges the next value and the increment of a sequence.ALTER SEQUENCE sequenceName [ RESTART WITH long ] [ INCREMENT BY long ]
ALTER TABLE ADDAdds a new column to a table.ALTER TABLE tableName ADD name dataType [ DEFAULT expression ]
[ [ NOT ] NULL ] [ AUTO_INCREMENT | IDENTITY ] [ BEFORE columnName ]
ALTER TABLE ADD CONSTRAINTAdds a constraint to a table.ALTER TABLE tableName ADD constraint [ CHECK | NOCHECK ]
ALTER TABLE ALTERChanges the data type of a column, rename a column,
change the identity value, or change the selectivity.
ALTER TABLE tableName ALTER COLUMN columnName
{ { dataType [ DEFAULT expression ] [ [ NOT ] NULL ] [ AUTO_INCREMENT | IDENTITY ] }
    | { RENAME TO name }
    | { RESTART WITH long }
    | { SELECTIVITY int }
    | { SET DEFAULT expression }
    | { SET NULL }
    | { SET NOT NULL } }
ALTER TABLE DROP COLUMNRemoves a column from a table.ALTER TABLE tableName DROP COLUMN columnName
ALTER TABLE DROP CONSTRAINTRemoves a constraint or a primary key from a table.ALTER TABLE tableName DROP { CONSTRAINT [ IF EXISTS ] constraintName | PRIMARY KEY }
ALTER TABLE SETDisables or enables referential integrity checking for a table.ALTER TABLE tableName SET REFERENTIAL_INTEGRITY
    { FALSE | TRUE [ CHECK | NOCHECK ] }
ALTER TABLE RENAMERenames a table.ALTER TABLE tableName RENAME TO newName
ALTER USER ADMINSwitches the admin flag of a user on or off.ALTER USER userName ADMIN { TRUE | FALSE }
ALTER USER RENAMERenames a user.ALTER USER userName RENAME TO newUserName
ALTER USER SET PASSWORDChanges the password of a user.ALTER USER userName SET { PASSWORD string | SALT bytes HASH bytes }
ALTER VIEWRecompiles a view after the underlying tables have been changed or created.ALTER VIEW viewName RECOMPILE
ANALYZEUpdates the selectivity statistics of all tables.ANALYZE [ SAMPLE_SIZE rowCountInt ]
COMMENTSets the comment of a database object.COMMENT ON
{ { COLUMN [ schemaName. ] tableName.columnName }
    | { { TABLE | VIEW | CONSTANT | CONSTRAINT | ALIAS | INDEX | ROLE
    | SCHEMA | SEQUENCE | TRIGGER | USER | DOMAIN } [ schemaName. ] objectName } }
IS expression
CREATE AGGREGATECreates a new user-defined aggregate function.CREATE AGGREGATE [ IF NOT EXISTS ] newAggregateName FOR className
CREATE ALIASCreates a new function alias.CREATE ALIAS [ IF NOT EXISTS ] newFunctionAliasName [ DETERMINISTIC ]
{ FOR classAndMethodName | AS sourceCodeString }
CREATE CONSTANTCreates a new constant.CREATE CONSTANT [ IF NOT EXISTS ] newConstantName VALUE expression
CREATE DOMAINCreates a new data type (domain).CREATE DOMAIN [ IF NOT EXISTS ] newDomainName AS dataType
[ DEFAULT expression ] [ [ NOT ] NULL ] [ SELECTIVITY selectivity ]
[ CHECK condition ]
CREATE INDEXCreates a new index.CREATE { [ UNIQUE ] [ HASH ] INDEX [ IF NOT EXISTS ] newIndexName
    | PRIMARY KEY [ HASH ] }
ON tableName ( indexColumn [,...] )
CREATE LINKED TABLECreates a table link to an external table.CREATE [ [ GLOBAL | LOCAL ] TEMPORARY ] LINKED TABLE [ IF NOT EXISTS ]
name ( driverString, urlString, userString, passwordString,
[ originalSchemaString, ] originalTableString ) [ EMIT UPDATES | READONLY ]
CREATE ROLECreates a new role.CREATE ROLE [ IF NOT EXISTS ] newRoleName
CREATE SCHEMACreates a new schema.CREATE SCHEMA [ IF NOT EXISTS ] name [ AUTHORIZATION ownerUserName ]
CREATE SEQUENCECreates a new sequence.CREATE SEQUENCE [ IF NOT EXISTS ] newSequenceName [ START WITH long ]
[ INCREMENT BY long ] [ CACHE long ]
CREATE TABLECreates a new table.CREATE [ CACHED | MEMORY ] [ TEMP | [ GLOBAL | LOCAL ] TEMPORARY ]
TABLE [ IF NOT EXISTS ] name
{ { ( { columnDefinition | constraint } [,...] ) [ AS select ] }
    | { AS select } }
[ ENGINE tableEngineName ] [ TRANSACTIONAL ] [ NOT PERSISTENT ]
CREATE TRIGGERCreates a new trigger.CREATE TRIGGER [ IF NOT EXISTS ] newTriggerName { BEFORE | AFTER | INSTEAD OF }
{ INSERT | UPDATE | DELETE | SELECT | ROLLBACK } [,...] ON tableName [ FOR EACH ROW ]
[ QUEUE int ] [ NOWAIT ] CALL triggeredClassName
CREATE USERCreates a new user.CREATE USER [ IF NOT EXISTS ] newUserName
{ PASSWORD string | SALT bytes HASH bytes } [ ADMIN ]
CREATE VIEWCreates a new view.CREATE [ OR REPLACE ] [ FORCE ] VIEW [ IF NOT EXISTS ] newViewName
[ ( columnName [,...] ) ] AS select
DROP AGGREGATEDrops an existing user-defined aggregate function.DROP AGGREGATE [ IF EXISTS ] aggregateName
DROP ALIASDrops an existing function alias.DROP ALIAS [ IF EXISTS ] existingFunctionAliasName
DROP ALL OBJECTSDrops all existing views, tables, sequences, schemas, function aliases, roles,
user-defined aggregate functions, domains, and users (except the current user).
DROP ALL OBJECTS [ DELETE FILES ]
DROP CONSTANTDrops a constant.DROP CONSTANT [ IF EXISTS ] constantName
DROP DOMAINDrops a data type (domain).DROP DOMAIN [ IF EXISTS ] domainName
DROP INDEXDrops an index.DROP INDEX [ IF EXISTS ] indexName
DROP ROLEDrops a role.DROP ROLE [ IF EXISTS ] roleName
DROP SCHEMADrops a schema.DROP SCHEMA [ IF EXISTS ] schemaName
DROP SEQUENCEDrops a sequence.DROP SEQUENCE [ IF EXISTS ] sequenceName
DROP TABLEDrops an existing table, or a list of tables.DROP TABLE [ IF EXISTS ] tableName [,...] [ CASCADE | RESTRICT ]
DROP TRIGGERDrops an existing trigger.DROP TRIGGER [ IF EXISTS ] triggerName
DROP USERDrops a user.DROP USER [ IF EXISTS ] userName
DROP VIEWDrops an existing view.DROP VIEW [ IF EXISTS ] viewName [ RESTRICT | CASCADE ]
TRUNCATE TABLERemoves all rows from a table.TRUNCATE TABLE tableName

No comments :

Post a Comment

Your Comment and Question will help to make this blog better...