Download presentation
Presentation is loading. Please wait.
Published byJeffrey Smith Modified over 9 years ago
1
SQL: DDL
2
SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation language –Manipulating user data: insert, update, select, etc. DCL - data control language –Control data access: permissions, etc.
3
3 SQL DDL DDL statements include –CREATE Table –ALTER Table –DROP Table
4
Create Table CREATE TABLE TableName ( ColumnDefinitions, Table Constraints )
5
5 Column Definition What to define? –Column name (required) –Data type and length (required) –Column constraints (optional): primary key, null, not null, default, unique, check Example FirstName VARCHAR(30) NOT NULL,
6
6 Data Types Data types are slightly different in many database products Data types reference –Access 2007: http://msdn.microsoft.com/en-us/library/bb208866.aspx –SQL Server 2005: http://msdn.microsoft.com/en-us/library/ms187752(SQL.90).aspx
7
Example
8
Example: Using Table Constraints
9
Example: Foreign Key
10
ALTER Table Alter Table TableName [Modification] Modification include –Add, modify, drop columns –Add, modify, drop table constraints
11
11 Altering Columns Adding a new column ALTER TABLE tablename ADD (column datatype); Modify a column ALTER TABLE tablename MODIFY (column newdatatype); ALTER TABLE Customer ADD (FNAME VARCHAR(30)); ALTER TABLE Customer MODIFY (FName VARCHAR(40)); Drop a column ALTER TABLE tablename DROP COLUMN colummname; ALTER TABLE Customer DROP COLUMN FName;
12
Altering Table Constraints Add a foreign key Alter table GroupAssignment add constraint GroupAssignment_FK2 foreign key(GroupNumber) references Groups(GroupId) on update cascade;
13
13 DROP Table DROP TABLE tablename; DROP TABLE Customer; Warning… The DROP statement will permanently remove table structure and all data
14
Summary Key concepts –DDL –Create –Alter –Drop –SQL Data types –Referential integrity, cascade
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.