# 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.

Slides:



Advertisements
Similar presentations
Session 2Introduction to Database Technology Data Types and Table Creation.
Advertisements

Creating Tables, Setting Constraints, and Datatypes What is a constraint and why do we use it? What is a datatype? What does CHAR mean? Page 97 in Course.
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 © by Royal Institute of Information Technology Introduction To Structured Query Language (SQL) 1.
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.
Beginning SQL Tutorial Author Jay Mussan-Levy. What is SQL?  Structured Query Language  Communicate with databases  Used to created and edit databases.
This course has taken from This unique introductory SQL tutorial not only provides easy-to-understand SQL instructions, but it allows.
SQL Data Definition II Stanislava Armstrong 1SQL Data Definition II.
Creating Database Tables © Abdou Illia MIS Spring /21/2015.
DT211 Stage 2 Databases Lab 1. Get to know SQL Server SQL server has 2 parts: –A client, running on your machine, in the lab. You access the database.
Database Design Concepts INFO1408 Term 2 week 1 Data validation and Referential integrity.
30-Jun-15 SQL A Brief Introduction. SQL SQL is Structured Query Language Some people pronounce SQL as “sequel” Other people insist that only “ess-cue-ell”
Creating Database Tables CS 320. Review: Levels of data models 1. Conceptual: describes WHAT data the system contains 2. Logical: describes HOW the database.
Structured Query Language SQL: An Introduction. SQL (Pronounced S.Q.L) The standard user and application program interface to a relational database is.
Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial Password: UWPstudent Password is case sensitive.
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,
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
Oracle Data Definition Language (DDL)
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
SQL data definition using Oracle1 SQL Data Definition using Oracle.
CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial.
SQL data definition using Oracle1 SQL Data Definition using Oracle.
Chapter 4 Introduction to MySQL. MySQL “the world’s most popular open-source database application” “commonly used with PHP”
CSC 2720 Building Web Applications Database and SQL.
Database Fred Durao What is a database? A database is any organized collection of data. Some examples of databases you may encounter in.
Oracle Data Definition Language (DDL) Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
CS146 References: ORACLE 9i PROGRAMMING A Primer Rajshekhar Sunderraman
Intro to SQL| MIS 2502  Spacing not relevant › BUT… no spaces in an attribute name or table name  Oracle commands keywords, table names, and attribute.
Topic 1: Introduction to SQL. SQL stands for Structured Query Language. SQL is a standard computer language for accessing and manipulating databases SQL.
Fox MIS Spring 2011 Database Week 5 SQL basics SELECT, INSERT, UPDATE, DELETE.
Tables and Constraints Oracle PL/SQL. Datatypes The SQL Data Definition Language Commands (or DDL) enable us to create, modify and remove database data.
Prince Sultan University Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
Lecture5: SQL Overview, Oracle Data Type, DDL and Constraints Ref. Chapter6 Lecture4 1.
SQL CREATING AND MANAGING TABLES lecture4 1. Database Objects ObjectDescription TableBasic unit of storage; composed of rows and columns ViewLogically.
Fox MIS Spring 2011 Database Week 6 ERD and SQL Exercise.
IS 380 Introduction to SQL This lectures covers material from: database textbook chapter 3 Oracle chapter: 3,14,17.
Sql DDL queries CS 260 Database Systems.
Defining NOT NULL and UNIQUE Constraints
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Aliya Farheen October 29,2015.
Constraints Lesson 8. Skills Matrix Constraints Domain Integrity: A domain refers to a column in a table. Domain integrity includes data types, rules,
# 1# 1 Moving SQL Data Across Applications How do you export and import data into or out of a database? What do we mean by.csv? CS 105 Spring 2010.
# 1# 1 QueriesQueries How do we ask questions of the data? What is SELECT? What is FROM? What is WHERE? What is a calculated field? Spring 2010 CS105.
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.
Introduction to MySQL Ullman Chapter 4. Introduction MySQL most popular open-source database application Is commonly used with PHP We will learn basics.
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.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
8 Copyright © 2005, Oracle. All rights reserved. Managing Schema Objects.
Constraints Advanced Database Systems Dr. AlaaEddin Almabhouh.
Lec-7. The IN Operator The IN operator allows you to specify multiple values in a WHERE clause. SQL IN Syntax SELECT column_name(s) FROM table_name WHERE.
Creating and Managing Tables. Database Objects ObjectDescription TableBasic unit of storage; composed of rows and columns ViewLogically represents subsets.
Relational Databases and SQL The relational model and the most common SQL commands.
CS 3630 Database Design and Implementation
Chapter 5 Introduction to SQL.
CS320 Web and Internet Programming SQL and MySQL
MIS2502: Data Analytics SQL – Putting Information Into a Database
Data Definition and Data Types
MIS2502: Data Analytics SQL – Putting Information Into a Database
STRUCTURED QUERY LANGUAGE
CS4222 Principles of Database System
SQL data definition using Oracle
MIS2502: Data Analytics SQL – Putting Information Into a Database
MIS2502: Data Analytics SQL – Putting Information Into a Database
CS3220 Web and Internet Programming SQL and MySQL
Chapter 4 Introduction to MySQL.
MIS2502: Data Analytics SQL 4– Putting Information Into a Database
Database Instructor: Bei Kang.
SQL NOT NULL Constraint
Presentation transcript:

# 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 Spring 2010

SQL commands below CS 105 Spring 2010 CREATE TABLE DemoForClass (FirstName varchar(12) NOT NULL default 'First Name', LastName varchar(12) NOT NULL default 'Last Name', Year year(4) NOT NULL default '2006', SSN varchar(11) NOT NULL default ' ')

What the table looks like CS 105 Spring 2010 Note: the name Kingfishersmith was truncated

Language explained CS 105 Spring 2010 CREATE TABLE tablename (column1 datatype, column2 datatype, column3 datatype ); create table means create a table ( begin defining fields with a ( ) end of fields is signaled by ) ; end of statement don’t forget the )

Creating a table in SQLyog Using a Wizard CS 105 Spring 2010

Language layout “field name" "datatype" [other constraints], ssn CHAR(11) NOT NULL,

Primary Key as shown in old client CS 105 Spring 2010 The Primary Key specifies the field that uniquely identifies each record in the Table

Setting a Primary Key A primary key is a column (field) that uniquely identifies the rest of the data in any given record. More than one field can be combined to establish a primary key (e.g., Deanne + Smith rather than Smith) (MySQL may give you trouble, but trust us) CS 105 Spring 2010

Validation, Constraints The database will automatically check that entered data is appropriate to the field type If the field is an item price, you can create a constraint that input is to be numbers only and no letters are allowed. We will not cover "Input Masks" this semester CS 105 Spring 2010 NOT NULL means that the column must have a value in each row. If NULL is used, that column may be left empty in a given row.

What is a constraint? A constraint is basically a rule associated with a column that the data entered into that column must follow. "Not Null" -- a column can't be left blank It is required See SAMS book, lessons 17 and 22 CS 105 Spring 2010

Popular datatypes – see Appendix D char(size) Fixed-length character string. Size is specified in parenthesis. Max 255 bytes. varchar(size) Variable-length character string. Max size is specified in parenthesis. VARCHAR(30) -- entry of varying length, maximum possible is 30 characters, can be less TEXT – a character string that does not have a fixed length CS 105 Spring 2010

More datatypes number(size) unsigned (no negative numbers) date Date value – Timestamp ---YYYY-MM-DD CS 105 Spring 2010

Number value in a field CS 105 Spring 2010 No negative numbers allowed, and field will not take letters! PK is for Primary Key Binary is for pictures, etc.

Default value in SQL CREATE TABLE tablestudents (FirstName VARCHAR (12) DEFAULT ‘First Name’ NOT NULL (etc.) CS 105 Spring 2010

NULL Values and calculations If you add a value to another value that is NULL, the answer that MySQL gives you is NULL! The same thing sometimes happens in our Compass GradeBook—if a score is missing, sometimes the total score is not computed. It all depends on what software you use. CS 105 Spring 2010

Adding Items Can Be Tricky CS 105 Spring 2010

Alter Table – Using a Query CS 105 Spring 2010 Adding a field….

Variation 1 of the Insert Statement If you know the order of the fields, you don’t have to specify the field names INSERT INTO Customers VALUES (' ', 'Village Toys', '200 Maple Lane', 'Detroit', 'MI', '44444', 'USA', 'John Smith', CS 105 Spring 2010

Variation 2 of Insert Statement You don’t have to insert a value for every field, unless it is a required (NOT NULL, PRIMARY KEY) field INSERT INTO Customers (cust_id, cust_name, cust_ ) VALUES (' ', 'Village Toys', CS 105 Spring 2010

Update Statement See page 131 and 132 of SAM’s book Modifies data in a table UPDATE players SET firstname= 'fred' WHERE ssn=' ' CS 105 Spring 2010

Before running Update CS 105 Spring 2010

After running the statement CS 105 Spring 2010

What did we learn? What is a constraint? How do we change information? Can a Primary Key be Null? CS 105 Spring 2010