SQL Server 2005 Implementation and Maintenance Chapter 3: Tables and Views.

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

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Copyright © by Royal Institute of Information Technology Introduction To Structured Query Language (SQL) 1.
Project Management Database and SQL Server Katmai New Features Qingsong Yao
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Introduction to Structured Query Language (SQL)
Introduction to Structured Query Language (SQL)
Introduction to Structured Query Language (SQL)
SQL DDL constraints Restrictions on the columns and tables 1SQL DDL Constraints.
Copyright ©2014 Pearson Education, Inc. Chapter 6 Physical Design Chapter6.1.
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,
SQL Basics. SQL SQL (Structured Query Language) is a special-purpose programming language designed from managing data in relational database management.
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 13 Managing Databases with SQL Server 2000.
CSE314 Database Systems More SQL: Complex Queries, Triggers, Views, and Schema Modification Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
HAP 709 – Healthcare Databases SQL Data Manipulation Language (DML) Updated Fall, 2009.
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.
Oracle Data Definition Language (DDL) Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
10 Copyright © 2009, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
1 Copyright © 2006, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
Copyright © 2004, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
5/24/01 Leveraging SQL Server 2000 in ColdFusion Applications December 9, 2003 Chris Lomvardias SRA International
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.
Views Lesson 7.
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 7 Introduction to Structured.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
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.
Introduction to Database System Adisak Intana Lecturer Chapter 7 : Data Integrity.
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.
06 | Modifying Data in SQL Server Brian Alderman | MCT, CEO / Founder of MicroTechPoint Tobias Ternstrom | Microsoft SQL Server Program Manager.
Visual Programing SQL Overview Section 1.
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
SQL CREATING AND MANAGING TABLES lecture4 1. Database Objects ObjectDescription TableBasic unit of storage; composed of rows and columns ViewLogically.
IMS 4212: Data Modeling—Attributes and Domains 1 Dr. Lawrence West, Management Dept., University of Central Florida Attributes and Domains.
Chapter 4 Indexes. Index Architecture  By default data is inserted on a first-come, first-serve basis  Indexes bring order to this chaos  Once you.
Constraints Lesson 8. Skills Matrix Constraints Domain Integrity: A domain refers to a column in a table. Domain integrity includes data types, rules,
Chapter 5 : Integrity And Security  Domain Constraints  Referential Integrity  Security  Triggers  Authorization  Authorization in SQL  Views 
Session 1 Module 1: Introduction to Data Integrity
ITS232 Introduction To Database Management Systems Siti Nurbaya Ismail Faculty of Computer Science & Mathematics, Universiti Teknologi MARA (UiTM), Kedah.
1 CS 430 Database Theory Winter 2005 Lecture 11: SQL DDL.
Module 8: Using Programming Objects for Data Retrieval.
Constraints Advanced Database Systems Dr. AlaaEddin Almabhouh.
Views / Session 3/ 1 of 40 Session 3 Module 5: Implementing Views Module 6: Managing Views.
What is your Character Data Type? March 5, 2016 John Deardurff Website:
Advanced SQL - DDL Advanced Database Dr. AlaaEddin Almabhouh.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
More SQL: Complex Queries,
Managing Tables, Data Integrity, Constraints by Adrienne Watt
Relational Database Design
Module 2: Creating Data Types and Tables
PL/SQL LANGUAGE MULITPLE CHOICE QUESTION SET-1
SQL Creating and Managing Tables
SQL Implementation & Administration
Module 5: Implementing Data Integrity by Using Constraints
Migrating a Disk-based Table to a Memory-optimized one in SQL Server
Proper DataType Usage = Guaranteed Better Performance and Accuracy
SQL Creating and Managing Tables
SQL Creating and Managing Tables
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Database systems Lecture 3 – SQL + CRUD
PT2520 Unit 5: Physical Design
Contents Preface I Introduction Lesson Objectives I-2
Relational Database Design
Presentation transcript:

SQL Server 2005 Implementation and Maintenance Chapter 3: Tables and Views

Tables  Tables hold all of the data  Tables are made of two smaller objects  Fields All data of a specific type  Records A group of related fields © Wiley Inc All Rights Reserved.

Datatypes  Datatypes restrict the types of data that a field can hold  Example: you can’t store letters in a field using the int datatype  You can store numbers in a char datatype field You cannot perform math on them though, they are just characters  There are several to choose from © Wiley Inc All Rights Reserved.

Datatypes, Cont.  Bit  Int  Bigint  Smallint  Tinyint  Decimal  Numeric  money © Wiley Inc All Rights Reserved.  Smallmoney  Float  Real  Datetime  Smalldatetime  Timestamp  Uniqueidentifier  Char  Varchar  Varchar(max)  Nchar  Nvarchar  Nvarchar(max)  Binary  Varbinary  Varbinary(max)

Datatypes, Cont.  Xml  Identity  Sql_variant  Table  Cursor  Computed columns © Wiley Inc All Rights Reserved.

Check Constraints  A T-SQL statement that Column-level – apply to column (cannot refer to other columns) Table-level – apply to table (cannot refer other tables)  Column-level restricts data that can be inserted in the field, even if it is the correct datatype Example: XZ is char data, but it is not a valid state abbreviation Check (GPA = 0) © Wiley Inc All Rights Reserved.

Add a check constraint CREATE TABLE dbo.Vendors (VendorID int PRIMARY KEY, VendorName nvarchar (50), CreditRating tinyint) GO ALTER TABLE dbo.Vendors ADD CONSTRAINT CK_Vendor_CreditRating CHECK (CreditRating >= 1 AND CreditRating <= 5)

Add a table level constraint CREATE TABLE CheckTbl (col1 int, col2 int); GO CREATE FUNCTION CheckFnctn() RETURNS int AS BEGIN int = COUNT(*) FROM CheckTbl END; GO ALTER TABLE CheckTbl ADD CONSTRAINT chkRowCount CHECK (dbo.CheckFnctn() >= 1 ); GO

Default Constraints  Used to fill in blank fields on an INSERT  Some considerations Can’t be used on columns with the timestamp datatype Can’t be used on IDENTITY columns. Can’t be used on columns with the ROWGUIDCOL property set © Wiley Inc All Rights Reserved.

Unique Constraints  These ensure that no duplicate values can be added to a field A field that holds social security number data may be a good candidate © Wiley Inc All Rights Reserved.

Partitioning Tables  Very useful for DSS, book’s examples are incorrect and incomplete --- SKIP © Wiley Inc All Rights Reserved.

Views  Described as a virtual table, or a stored SELECT query  Views represent the data stored in a table  They do not hold data themselves  Useful when you do not want to show all available data © Wiley Inc All Rights Reserved.

Modifying Data With Views  Views can be used to modify data  If you use a view to modify data, the modification can affect only one base table at a time.  You can't modify data in a view that uses aggregate functions.  If you try to insert a record into a view that doesn't show all fields, and those fields do not accept NULL values, your insert will fail. © Wiley Inc All Rights Reserved.

Indexed Views  Each time a view is queried it must be materialized SQL Server must gather the data from the table to show the user  This can be a costly process for complex views  Indexing a view creates a pre-materialized view in the database © Wiley Inc All Rights Reserved.

Indexed View Considerations  The ANSI_NULLS and QUOTED_IDENTIFIER options must be turned on when the view is created. To do this, use the sp_dboption stored procedure:  The ANSI_NULLS option must have been turned on during the creation of all the tables that are referenced by the view.  The view can't reference other views, only tables.  Any user-defined function's data access property must be NO SQL and external access property must be NO.  All the tables referenced by the view must be in the same database as the view and must have the same owner as the view © Wiley Inc All Rights Reserved.

Indexed View Considerations, Cont.  The view must be created with the SCHEMABINDING option. This option prohibits the schema of the base tables from being changed (adding or dropping a column, for instance).  Any user-defined functions referenced in the view must have been created with the SCHEMABINDING option as well.  All objects in the view must be referenced by their two-part names: owner.object. No one-, three-, or four-part names are allowed.  Any functions referenced in an indexed view must be deterministic, which means they return the same value each time they're invoked with the same arguments © Wiley Inc All Rights Reserved.

Indexed View Select Statement  Column names must be explicitly stated in the SELECT statement; you can't use * or tablename.* to access columns.  You may not reference a column twice in the SELECT statement unless all or all but one reference to the column is made in a complex expression.  You may not use a derived table that comes from using a SELECT statement encased in parentheses in the FROM clause of a SELECT statement.  You can't use ROWSET, UNION, TOP, ORDER BY, DISTINCT, COUNT(*), COMPUTE, or COMPUTE BY. © Wiley Inc All Rights Reserved.

Indexed View Select Statement, Cont.  Subqueries and outer or self JOINs can't be used.  The AVG, MAX, MIN, STDEV, STDEVP, VAR, and VARP aggregate functions aren't allowed in the SELECT statement.  A SUM() that references a nullable expression isn't allowed.  CONTAINS and FREETEXT aren't allowed in the SELECT statement.  If you use GROUP BY, you can't use HAVING, ROLLUP, or CUBE, and you must use COUNT_BIG() in the select list. © Wiley Inc All Rights Reserved.