SlideShare a Scribd company logo
Data Definition Language
CIS-182
DDL
• Data Definition Language: Work with Objects
– Objects are Database, Tables
• Three commands for objects
– Create an object
– Alter an object
– Delete an object
– Follow command with type then name
• CREATE TABLE Students
Database
• Must create container first
– Not all vendors use databases, may be defined as a
SCHEMA
• Optional Parameters depend on vendor
– Parameter is a value passed to a command
• Similar to an argument in other languages
– Can create database without optional parameters
3
CREATE SQL SERVER DATABASE
• Must have name
• Can specify filenames and locations
– SQL Server uses two files
• Data file (.mdf) to store objects and data
• Log file (.ldf) to track actions applied to database
– Can specify file characteristics, such as growth
– Files can be organized into groups
• Have at least one file group
• Aid to manage across machines
MS CREATE DATABASE
CREATE DATABASE database_name
[ ON
[ < filespec > [ ,...n ] ]
[ , < filegroup > [ ,...n ] ]
]
[ LOG ON { < filespec > [ ,...n ] } ]
[ COLLATE collation_name ]
[ FOR LOAD | FOR ATTACH ]
Placeholder Definitions
< filespec > ::=
[ PRIMARY ]
( [ NAME = logical_file_name , ]
FILENAME = 'os_file_name'
[ , SIZE = size ]
[ , MAXSIZE = { max_size | UNLIMITED } ]
[ , FILEGROWTH = growth_increment ] )
[ ,...n ]
< filegroup > ::=
FILEGROUP filegroup_name < filespec > [ ,...n ]
Create Table
• Table must include a field list
– At least one field
– List values are separated by comma
– List begin/end defined by parentheses
• Persistent v. Temporary
– Persistent tables store data even when not in use
– Temporary tables have data available at certain times
• Usually used in stored procedures, reporting
Fields
• Field must have a name and datatype
– Datatype can be predefined, user defined or
constructed
– Sample Predefined (built-in) datatypes:
• CHAR
• INT
• SMALLDATETIME
• See Books Online for complete list
String Datatypes
• Strings datatypes store any character
• Should field be fixed-width?
– CHAR is fixed width, if a value is shorter than field
size the remaining positions will have spaces entered
– VARCHAR is variable width, only the value is stored
to the maximum number of characters
Unicode/National Character Set
• Do text values include characters other than
those typically found in English words?
– “N” stands for National Character Set
– Each character takes twice as much storage
– CHAR v. NCHAR
• Char: Fixed width field for storing “standard” characters
• NCHAR: Fixed width field for storing characters from any
language
– Also have NVARCHAR for varying-width fields
Number Datatypes
• Use the following questions to determine the
datatype needed for numeric fields
– Does a field store a whole number or fraction (or
exponent)?
• Whole number datatypes include INT, SMALLINT
• Fractions include DECIMAL, REAL
– Exact or approximate?
• SMALLINT, INT store actual values
• FLOAT, REAL store approximate values
– What are the largest/smallest values?
• INT stores a larger value than SMALLINT
Create Table Example
CREATE TABLE Students
(StudentID CHAR(9),
LastName VARCHAR(35),
FirstName VARCHAR(25))
• Table name is Students
• Fields are a list (enclosed in parentheses)
– Student ID is a fixed-width field with 9 spaces
– Last name is a variable-width field with space for up
to 35 characters

More Related Content

PDF
Microsoft power point chapter 5 file edited
PPTX
Oceangraphic data formats
PPTX
Moving Data to and From R
PPT
VCAL Databases
PPTX
File Structure Concepts
PPT
Fundamental file structure concepts &amp; managing files of records
PPTX
Introduction to ms access database
PPT
Databasesmycopy
Microsoft power point chapter 5 file edited
Oceangraphic data formats
Moving Data to and From R
VCAL Databases
File Structure Concepts
Fundamental file structure concepts &amp; managing files of records
Introduction to ms access database
Databasesmycopy

What's hot (15)

PPTX
31cs
PPT
Introduction to the design and specification of file structures
PPTX
Array in c
PDF
New in Hadoop: You should know the Various File Format in Hadoop.
PPT
New diskmgmt
PDF
[Altibase] 4-1 tablespace concept
PDF
Aaa ped-6-Data manipulation: Data Files, and Data Cleaning & Preparation
PPTX
MS Access Intro
PPTX
Reading and Writing Files
PPT
Computers12 Ch6
DOCX
Switching & Multiplexing
PPSX
Archive Recovery Software
PPT
Unesco information storage and retrievals tools
PPT
Backing storage
PPT
Data Types And Field Properties
31cs
Introduction to the design and specification of file structures
Array in c
New in Hadoop: You should know the Various File Format in Hadoop.
New diskmgmt
[Altibase] 4-1 tablespace concept
Aaa ped-6-Data manipulation: Data Files, and Data Cleaning & Preparation
MS Access Intro
Reading and Writing Files
Computers12 Ch6
Switching & Multiplexing
Archive Recovery Software
Unesco information storage and retrievals tools
Backing storage
Data Types And Field Properties
Ad

Viewers also liked (10)

PPT
Data manipulation language
PDF
Part 7 ddl dan dml lant..retriving data up
PPT
Wb Presentation
PPT
Warren Buffet - Interesting Aspects of His Life
PPTX
Dbms
PPT
Warren Buffet
PPT
Ch 12 O O D B Dvlpt
PPTX
Data definition language postgreSQL
PPTX
Data definition language (ddl)
PDF
Part 6 ddl dan dml (case studiies)
Data manipulation language
Part 7 ddl dan dml lant..retriving data up
Wb Presentation
Warren Buffet - Interesting Aspects of His Life
Dbms
Warren Buffet
Ch 12 O O D B Dvlpt
Data definition language postgreSQL
Data definition language (ddl)
Part 6 ddl dan dml (case studiies)
Ad

Similar to 4 create database (20)

PDF
Introduction to HDF5 Data Model, Programming Model and Library APIs
PPT
Parquet and impala overview external
PPTX
Web Application Development using PHP Chapter 6
PPT
Sas short course_presentation_11-4-09
PPT
Sas short course_presentation_11-4-09
PPTX
SQL-1.pptx for database system and system query language
PPTX
SQL.pptx structure query language in database management system
PPT
1650607.ppt
PPTX
unit-ii.pptx
PPTX
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
PDF
PPT
Database (IT) Lecture Slide
PPTX
INTRODUCTION TO DATABASE............pptx
PPT
Data Indexing Presentation-My.pptppt.ppt
PPT
Implementing the Databese Server session 02
PPTX
Pandas
PPTX
Unit 10 - Realtional Databases.pptxxxxxxxxx
PDF
Apache Hive, data segmentation and bucketing
PPTX
GRADE 10 MS ACCESS.pptxdadadadadadadadada
PPTX
SQL Server 2014 Memory Optimised Tables - Advanced
Introduction to HDF5 Data Model, Programming Model and Library APIs
Parquet and impala overview external
Web Application Development using PHP Chapter 6
Sas short course_presentation_11-4-09
Sas short course_presentation_11-4-09
SQL-1.pptx for database system and system query language
SQL.pptx structure query language in database management system
1650607.ppt
unit-ii.pptx
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
Database (IT) Lecture Slide
INTRODUCTION TO DATABASE............pptx
Data Indexing Presentation-My.pptppt.ppt
Implementing the Databese Server session 02
Pandas
Unit 10 - Realtional Databases.pptxxxxxxxxx
Apache Hive, data segmentation and bucketing
GRADE 10 MS ACCESS.pptxdadadadadadadadada
SQL Server 2014 Memory Optimised Tables - Advanced

More from Randy Riness @ South Puget Sound Community College (20)

Recently uploaded (20)

PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Cloud computing and distributed systems.
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
KodekX | Application Modernization Development
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Empathic Computing: Creating Shared Understanding
PDF
Electronic commerce courselecture one. Pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Cloud computing and distributed systems.
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
NewMind AI Weekly Chronicles - August'25 Week I
KodekX | Application Modernization Development
Dropbox Q2 2025 Financial Results & Investor Presentation
20250228 LYD VKU AI Blended-Learning.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
The Rise and Fall of 3GPP – Time for a Sabbatical?
MIND Revenue Release Quarter 2 2025 Press Release
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Understanding_Digital_Forensics_Presentation.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Big Data Technologies - Introduction.pptx
Spectral efficient network and resource selection model in 5G networks
Empathic Computing: Creating Shared Understanding
Electronic commerce courselecture one. Pdf

4 create database

  • 2. DDL • Data Definition Language: Work with Objects – Objects are Database, Tables • Three commands for objects – Create an object – Alter an object – Delete an object – Follow command with type then name • CREATE TABLE Students
  • 3. Database • Must create container first – Not all vendors use databases, may be defined as a SCHEMA • Optional Parameters depend on vendor – Parameter is a value passed to a command • Similar to an argument in other languages – Can create database without optional parameters 3
  • 4. CREATE SQL SERVER DATABASE • Must have name • Can specify filenames and locations – SQL Server uses two files • Data file (.mdf) to store objects and data • Log file (.ldf) to track actions applied to database – Can specify file characteristics, such as growth – Files can be organized into groups • Have at least one file group • Aid to manage across machines
  • 5. MS CREATE DATABASE CREATE DATABASE database_name [ ON [ < filespec > [ ,...n ] ] [ , < filegroup > [ ,...n ] ] ] [ LOG ON { < filespec > [ ,...n ] } ] [ COLLATE collation_name ] [ FOR LOAD | FOR ATTACH ]
  • 6. Placeholder Definitions < filespec > ::= [ PRIMARY ] ( [ NAME = logical_file_name , ] FILENAME = 'os_file_name' [ , SIZE = size ] [ , MAXSIZE = { max_size | UNLIMITED } ] [ , FILEGROWTH = growth_increment ] ) [ ,...n ] < filegroup > ::= FILEGROUP filegroup_name < filespec > [ ,...n ]
  • 7. Create Table • Table must include a field list – At least one field – List values are separated by comma – List begin/end defined by parentheses • Persistent v. Temporary – Persistent tables store data even when not in use – Temporary tables have data available at certain times • Usually used in stored procedures, reporting
  • 8. Fields • Field must have a name and datatype – Datatype can be predefined, user defined or constructed – Sample Predefined (built-in) datatypes: • CHAR • INT • SMALLDATETIME • See Books Online for complete list
  • 9. String Datatypes • Strings datatypes store any character • Should field be fixed-width? – CHAR is fixed width, if a value is shorter than field size the remaining positions will have spaces entered – VARCHAR is variable width, only the value is stored to the maximum number of characters
  • 10. Unicode/National Character Set • Do text values include characters other than those typically found in English words? – “N” stands for National Character Set – Each character takes twice as much storage – CHAR v. NCHAR • Char: Fixed width field for storing “standard” characters • NCHAR: Fixed width field for storing characters from any language – Also have NVARCHAR for varying-width fields
  • 11. Number Datatypes • Use the following questions to determine the datatype needed for numeric fields – Does a field store a whole number or fraction (or exponent)? • Whole number datatypes include INT, SMALLINT • Fractions include DECIMAL, REAL – Exact or approximate? • SMALLINT, INT store actual values • FLOAT, REAL store approximate values – What are the largest/smallest values? • INT stores a larger value than SMALLINT
  • 12. Create Table Example CREATE TABLE Students (StudentID CHAR(9), LastName VARCHAR(35), FirstName VARCHAR(25)) • Table name is Students • Fields are a list (enclosed in parentheses) – Student ID is a fixed-width field with 9 spaces – Last name is a variable-width field with space for up to 35 characters