80 likes | 389 Views
SQL Data Definition Language (DDL). Data definition language. SQL Structured Query Language ISO / ANSI standard SQL = DDL + DML DDL = Data Definition Language A part of SQL Used to create objects in the database Database, table, view, etc . General syntax Create object_type object_name
E N D
SQL Data Definition Language (DDL) SDL Data Definition Language (DDL)
Data definition language • SQL • Structured Query Language • ISO / ANSI standard • SQL = DDL + DML • DDL = Data Definition Language • A part of SQL • Used to create objects in the database • Database, table, view, etc. • General syntax • Create object_type object_name • Create table someName … • Alter table someName • Drop table someName SDL Data Definition Language (DDL)
Create table general syntax • Create table someName( firstColumn datatype constraints, secondColumn datatype constraints, …. ) SDL Data Definition Language (DDL)
Special data types • PK (primarykey) • NN (Null / not null) • Where null is allowed (or not) for the field • UQ (Unique index) • AI Auto Incremental • Used to generate number • Usually for generation of primary key values • Works with int • Default • The field has a default value • Used if the user does not supply any data in the INSERT statement SDL Data Definition Language (DDL)
Drop table • Deletes an existing table • All the data will be deleted as well! • No possible if other tables are referring (foreign keys) the deleted table SDL Data Definition Language (DDL)
Alter table • Used to change and existing table • Add / remove columns • Add / remove constraints • Fairly complex syntax • If the table is empty it might be easier to drop an re-create the table SDL Data Definition Language (DDL)
Using the GUI Tool • MS Sql Workbench has a GUI tool for creating, altering and dropping table, etc. • Create the tables with relevant columns SDL Data Definition Language (DDL)