Data Definition Language

Slides:



Advertisements
Similar presentations
Data Definition Language (DDL)
Advertisements

1 SQL Server Management Studio SQL DDL CREATE TABLE Constraints ALTER TABLE DROP TABLE The GUI way Steen Jensen, autumn 2013.
Let’s try Oracle. Accessing Oracle The Oracle system, like the SQL Server system, is client / server. For SQL Server, –the client is the Query Analyser.
SQL components In Oracle. SQL in Oracle SQL is made up of 4 components: –DDL Data Definition Language CREATE, ALTER, DROP, TRUNCATE. Creates / Alters.
Using Relational Databases and SQL
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 9: Data Definition Language.
Murali Mani SQL DDL and Oracle utilities. Murali Mani Datatypes in SQL INT (or) INTEGER FLOAT (or) REAL DECIMAL (n, m) CHAR (n) VARCHAR (n) DATE, TIME.
SQL Table Basics. Database Objects Tables Temporary tables (begin with #) Views Keys Indexes.
SQL DDL constraints Restrictions on the columns and tables 1SQL DDL Constraints.
Database Management System LICT 3011 Eyad H. Elshami.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 10: Data Definition Language.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2010 All Rights Reserved. 1.
Introduction to SQL  SQL or sequel  It is a standardised language with thousands of pages in the standard  It can be in database system through GUI,
Oracle Data Definition Language (DDL)
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Chapter 9 SQL and RDBMS Part C. SQL Copyright 2005 Radian Publishing Co.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Database Design lecture 3_1 1 Database Design Lecture 3_1 Data definition in SQL.
Introduction to MySQL Lab no. 10 Advance Database Management System.
Oracle Data Definition Language (DDL) Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
SQL Data Definition Language (DDL) Using Microsoft SQL Server 1SDL Data Definition Language (DDL)
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
SQL Basics. 5/27/2016Chapter 32 of 19 Naming SQL commands are NOT case sensitive SQL commands are NOT case sensitive But user identifier names ARE case.
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
Visual Programing SQL Overview Section 1.
1 DBS201: More on SQL Lecture 3. 2 Agenda How to use SQL to update table definitions How to update data in a table How to join tables together.
Altering Tables and Constraints Database Systems Objectives Add and modify columns. Add, enable, disable, or remove constraints. Drop a table. Remove.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
IS6146 Databases for Management Information Systems Lecture 3: SQL III – The DDL Rob Gleasure robgleasure.com.
Starting with Oracle SQL Plus. Today in the lab… Connect to SQL Plus – your schema. Set up two tables. Find the tables in the catalog. Insert four rows.
UNIVERSITAS BINA DARMA 2013 DATA DEFINITION LANGUAGE (DDL)
Physical Model Lecture 11. Physical Data Model The last step is the physical design phase, In this phase data is – Store – Organized and – Access.
Creating and Managing Tables. Database Objects ObjectDescription TableBasic unit of storage; composed of rows and columns ViewLogically represents subsets.
Fundamentals of DBMS Notes-1.
Rob Gleasure robgleasure.com
Fundamental of Database Systems
Rob Gleasure robgleasure.com
Managing Tables, Data Integrity, Constraints by Adrienne Watt
Data Definition and Data Types
SQL: Schema Definition and Constraints Chapter 6 week 6
The Basics of Data Manipulation
Insert, Update and the rest…
SQL Creating and Managing Tables
Designing Tables for a Database System
ORACLE SQL Developer & SQLPLUS Statements
SQL Creating and Managing Tables
Lecturer: Mukhtar Mohamed Ali “Hakaale”
لغة قواعد البيانات STRUCTURED QUERY LANGUAGE SQL))
SQL Creating and Managing Tables
CS4222 Principles of Database System
The Basics of Data Manipulation
DATABASE SQL= Structure Query Language مبادئ قواعد بيانات
CS122 Using Relational Databases and SQL
Oracle Data Definition Language (DDL)
CS122 Using Relational Databases and SQL
Chapter 2: Creating And Modifying Database Tables
CS1222 Using Relational Databases and SQL
Data Definition Language
Chapter # 7 Introduction to Structured Query Language (SQL) Part I.
CS122 Using Relational Databases and SQL
MIS2502: Data Analytics SQL 4– Putting Information Into a Database
CS1222 Using Relational Databases and SQL
CS122 Using Relational Databases and SQL
IST 318 Database Administration
Instructor: Samia arshad
Structured Query Language Path from Unorganized to Organized….
CS122 Using Relational Databases and SQL
CS122 Using Relational Databases and SQL
SQL (Structured Query Language)
Presentation transcript:

Data Definition Language Randy Moss

Agenda Learn how databases are created Create and alter the field structure of tables Create and drop primary key constraints Create and drop default constraints Create and drop check constraints Create and drop foreign key constraints Create and drop indexes Create and drop views Learn about stored procedures and triggers Save and use DDL in scripts

Database Definition Language (DDL) Subset of SQL commands to create and modify database objects Can create an entire database using SQL rather than a graphical user interface With DDL you gain more control over exactly what database obejcts are built and what they are named DDL saved into a script can be easily ported from one database installation to another

Naming tips Using consistent names Do not include spaces in your table or fields Avoid the use of SQL reserved words and punctuation marks in table and field names Keep names short, but long enough to be descriptive Be consistent in your use of abbreviations Name primary key and foreign key fields consistently Avoid generic field names, such as ID or Date

Creating a Table Syntax: CREATE TABLE tableName ( ) fieldname datatype null | not null, fieldname datatype null | not null )

Example of Creating a Table CREATE TABLE Contracts ( ArtistID Integer NOT NULL, ContractDate DateTime NOT NULL );

Dropping a Table DROP TABLE tableName; Example: DROP TABLE Contracts;

Adding Columns to an Existing Table Syntax: ALTER TABLE tableName ADD columnName dataType null | not null; Example: ALTER TABLE Contracts ADD ContractType VarChar(10) NULL;

Altering Existing Columns in a Table Syntax: ALTER TABLE {tableName} MODIFY COLUMN {columnName} {dataType} {null | not null}; Example: # Change the length on the ContractType field to 15 in the Contracts Table ALTER TABLE Contracts MODIFY ContractType VarChar(15);

Dropping a Column Syntax: ALTER TABLE {tableName} DROP COLUMN {columnName}; Example: # Remove the ContractType column from Contracts table ALTER TABLE Contracts DROP COLUMN ContractType;

Columns and Sequences Techniques to automatically generated a sequential number with each row that is inserted Never have to insert a value to it, but it will always be unique within the table Make excellent primary key in cases where there is no naturally occurring primary key

Column Sequence Example CREATE TABLE tbl ( ID int AUTO_INCREMENT NOT NULL, anotherField int null, primary key(ID) );

Sequences Vs. Guid Columns An identity column (or sequence) is unique within a given a table in a given database on a given server With distributed database, identity column may not\be unique across every instance of the table One solution is to use the identity column in conjunction with a locationID as the primary key Another solution Globally Unique Identifier (GUID), which is supported in some databases A GUID is a 16-byte ID guaranteed to be unique across every instance of a distributed database GUIDs are cumbersome to work with: C1C5FCE2-879E-4A96-B845- 9F3FC4A10EC8