Module 3: Creating Data Types and Tables. Overview Working with Data Types Working with Tables Generating Column Values Generating Scripts.

Slides:



Advertisements
Similar presentations
9 Creating and Managing Tables. Objectives After completing this lesson, you should be able to do the following: Describe the main database objects Create.
Advertisements

MS-Access XP Lesson 1. Introduction to MS-Access Database Management System Software (DBMS) Store data in databases Database is a collection of table.
Copyright  Oracle Corporation, All rights reserved. 10 Creating and Managing Tables.
Module 6 Implementing Table Structures in SQL Server ®2008 R2.
Module 4: Creating Data Types and Tables. Overview Creating Data Types Creating Tables Generating Column Values Generating Scripts.
SQL components In Oracle. SQL in Oracle SQL is made up of 4 components: –DDL Data Definition Language CREATE, ALTER, DROP, TRUNCATE. Creates / Alters.
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.
Creating Tables, Defining Constraints Rose-Hulman Institute of Technology Curt Clifton.
SQL Overview Defining a Schema CPSC 315 – Programming Studio Spring 2008 Project 1, Lecture 3 Slides adapted from those used by Jeffrey Ullman, via Jennifer.
1 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management.
Copyright ©2014 Pearson Education, Inc. Chapter 6 Physical Design Chapter6.1.
Database Constraints. Database constraints are restrictions on the contents of the database or on database operations Database constraints provide a way.
DATABASES AND SQL. Introduction Relation: Relation means table(data is arranged in rows and columns) Domain : A domain is a pool of values appearing in.
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,
Overview What is SQL Server? Creating databases Administration Security Backup.
Module 2 Working with Data Types. Module Overview Using Data Types Working with Character Data Converting Data Types Working with Specialized Data Types.
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 13 Managing Databases with SQL Server 2000.
Module 3: Changes to Transact-SQL. Overview Accessing Object Information New Transact-SQL Syntax Changes to Objects Distributed Queries.
Irwin/McGraw-Hill Copyright © 2000 The McGraw-Hill Companies. All Rights reserved Whitten Bentley DittmanSYSTEMS ANALYSIS AND DESIGN METHODS5th Edition.
Irwin/McGraw-Hill Copyright © 2000 The McGraw-Hill Companies. All Rights reserved Whitten Bentley DittmanSYSTEMS ANALYSIS AND DESIGN METHODS5th Edition.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Chapter 7 SQL HUANG XUEHUA. SQL SQL server2005 introduction Install components  management studio.
Module 1: Introduction to Transact-SQL
© 2007 by Prentice Hall3-1 Introduction to Oracle 10g Chapter 3 Creating, Modifying, Renaming, and Deleting Database Tables James Perry and Gerald Post.
Oracle Data Definition Language (DDL) Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
Module 5 Planning for SQL Server® 2008 R2 Indexing.
Module 3 Designing a Physical Database Model. Module Overview Selecting Data Types Designing Database Tables Designing Data Integrity.
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.
Unit 6 Data Storage Design. Key Concepts 1. Database overview 2. SQL review 3. Designing fields 4. Denormalization 5. File organization 6. Object-relational.
11 3 / 12 CHAPTER Databases MIS105 Lec15 Irfan Ahmed Ilyas.
Copyright  Oracle Corporation, All rights reserved. 10 Creating and Managing Tables.
Indexes / Session 2/ 1 of 36 Session 2 Module 3: Types of Indexes Module 4: Maintaining Indexes.
Module 3 Designing and Implementing Tables. Module Overview Designing Tables Working with Schemas Creating and Altering Tables.
Data Types Lesson 4. Skills Matrix Table A table stores your data. Tables are relational in that they are organized as rows and columns (a matrix). Each.
SQL Server 2005 Implementation and Maintenance Chapter 3: Tables and Views.
Introduction to Database System Adisak Intana Lecturer Chapter 7 : Data Integrity.
Module 4: Implementing Data Integrity
CREATE TABLE CREATE TABLE statement is used for creating relations Each column is described with three parts: column name, data type, and optional constraints.
Session 11 Creating Tables and Using Data Types. RDBMS and Data Management/Session 11/2 of 40 Session Objectives Define the data types and list the categories.
SQL: Part 1 Original materials supplied by the Oracle Academic Initiative (OAI). Edited for classroom use by Professor Laku Chidambaram. Not for commercial.
# 1# 1 Creating Tables, Setting Constraints, and Datatypes What is a constraint and why do we use it? What is a datatype? What does CHAR mean? CS 105.
6 Copyright © 2005, Oracle. All rights reserved. Managing Schema Objects.
Visual Programing SQL Overview Section 1.
GLOBEX INFOTEK Copyright © 2013 Dr. Emelda Ntinglet-DavisSYSTEMS ANALYSIS AND DESIGN METHODSINTRODUCTORY SESSION EFFECTIVE DATABASE DESIGN for BEGINNERS.
Sql DDL queries CS 260 Database Systems.
IMS 4212: Data Modeling—Attributes and Domains 1 Dr. Lawrence West, Management Dept., University of Central Florida Attributes and Domains.
Session 1 Module 1: Introduction to Data Integrity
©Silberschatz, Korth and Sudarshan1 Structured Query Language (SQL) Data Definition Language Domains Integrity Constraints.
Chapter 4 Indexes. Indexes Logically represents subsets of data from one or more tables View Generates numeric valuesSequence Basic unit of storage; composed.
1 CS 430 Database Theory Winter 2005 Lecture 11: SQL DDL.
Basic SQL*Plus edit and execute commands SQL*Plus buffer and built-in editor holds the last SQL statement Statements are created in free-flow style and.
Lecture # 24 Introduction to SQL Muhammad Emran Database Systems.
8 Copyright © 2005, Oracle. All rights reserved. Managing Schema Objects.
CDT/1 Creating data tables and Referential Integrity Objective –To learn about the data constraints supported by SQL2 –To be able to relate tables together.
Advanced SQL - DDL Advanced Database Dr. AlaaEddin Almabhouh.
Creating Database Objects
Managing Tables, Data Integrity, Constraints by Adrienne Watt
Module 2: Creating Data Types and Tables
Data Definition and Data Types
SQL OVERVIEW DEFINING A SCHEMA
Chapter 4 Indexes.
CH 4 Indexes.
CIS16 Application Programming with Visual Basic
PT2520 Unit 5: Physical Design
CH 4 Indexes.
Creating Database Objects
Presentation transcript:

Module 3: Creating Data Types and Tables

Overview Working with Data Types Working with Tables Generating Column Values Generating Scripts

Lesson: Working with Data Types System-Supplied Data Types User-Defined Data Types Guidelines for Specifying Data Types

System-Supplied Data Types Numeric  Integer  Exact numeric  Approximate numeric  Monetary Date and Time Character and Unicode Character Binary Other

User-Defined Data Types Dropping Creating EXEC sp_addtype city, 'nvarchar(15)', NULL EXEC sp_addtype region, 'nvarchar(15)', NULL EXEC sp_addtype country, 'nvarchar(15)', NULL EXEC sp_addtype city, 'nvarchar(15)', NULL EXEC sp_addtype region, 'nvarchar(15)', NULL EXEC sp_addtype country, 'nvarchar(15)', NULL EXEC sp_droptype city

Guidelines for Specifying Data Types Specify Narrowest Column Possible If Column Length Varies, Use a Variable Data Type Use tinyint Appropriately In General, Use decimal For Numeric Data Types If Storage Is Greater Than 8000 Bytes, Use text or image Use money for Currency Do Not Use float or real as Primary Keys

Lesson: Working with Tables How SQL Server Organizes Data in Rows How SQL Server Organizes Variable-Length Data Table Creation and Deletion Process Column Addition and Removal Process

How SQL Server Organizes Data in Rows HeaderFixed DataNBVBVariable Data Null Block Variable Block 4 bytes Data

How SQL Server Organizes Variable-Length Data block 1block 2block 1block 2 Data row Intermediate Node Root Structure Text Pointer

Creating a Table Column Collation Specifying NULL or NOT NULL Computed Columns Dropping a Table Table Creation and Deletion Process Column nameData type NULL or NOT NULL CREATE TABLE dbo.Categories (CategoryID CategoryName Description Picture int IDENTITY (1,1) nvarchar(15) ntext ImageNOT NULL, NULL, NULL)

Column Addition and Removal Process ALTER TABLE CategoriesNew ADD Commission money null ADD ALTER TABLE CategoriesNew DROP COLUMN Sales_date DROP Customer_nameSales_amountSales_dateCustomer IDCommission

Lesson: Generating Column Values The Identity Property The NEWID Function and the uniqueidentifier Data Type

The Identity Property Requirements for Using the Identity Property  Only one identity column is allowed per table  Use with integer, numeric, and decimal data types Retrieving Information About the Identity Property  Use IDENT_SEED and IDENT_INCR for definition information  Use SCOPE_IDENTITY to determine most recent value Managing the Identity Property

The NEWID Function and the uniqueidentifier Data Type These Features Are Used Together Ensure Globally Unique Values Use with the DEFAULT Constraint Use with distributed and replicated databases May degrade performance if used as primary key CREATE TABLE Customer (CustID uniqueidentifier NOT NULL DEFAULT NEWID(), CustName char(30) NOT NULL) CREATE TABLE Customer (CustID uniqueidentifier NOT NULL DEFAULT NEWID(), CustName char(30) NOT NULL)

Lesson: Generating Scripts Uses of Generated Database Schema Scripts Script Generation Process

Uses of Generated Database Schema Scripts Maintain backup script Create or update a database development script Create a test or development environment Train new employees

Script Generation Process SQL Enterprise Manager  Entire database into single script file  Table-only schema  Table and index schema SQL Analyzer  One object at a time

Lab A: Creating Data Types and Tables Exercise 1: Creating User-Defined Data Types Exercise 2: Creating Tables in the ClassNorthwind Database Exercise 3: Adding and Dropping Columns Exercise 4: Generating Transact-SQL Scripts Exercise 5: Loading the ClassNorthwind Database with Data