+ All Categories

Tables

Date post: 23-Mar-2016
Category:
Upload: ossie
View: 54 times
Download: 1 times
Share this document with a friend
Description:
Tables. Lesson 6. Skills Matrix. Tables. Tables store data. Tables are relational They store data organized as row and columns. - PowerPoint PPT Presentation
Popular Tags:
23
Tables Tables Lesson 6
Transcript
Page 1: Tables

TablesTablesLesson 6

Page 2: Tables

Skills MatrixSkills Matrix

Page 3: Tables

TablesTables• Tables store data. • Tables are relational

– They store data organized as row and columns.

– Data can be retrieved efficiently because the RDBMS can locate a specific field (the intersection of a row and column) without having the read the entire table (as in a flat-file database system).

Page 4: Tables
Page 5: Tables

Creating TablesCreating Tables1. Open SQL Server Management

Studio. In Object Explorer, expand Server Databases MSSQL_Training.

2. Right-click the Tables icon and select New Table to open the Table Designer.

• Tables are often created using SQL scripts containing CREATE TABLE commands.

Page 6: Tables

Options when Creating TablesOptions when Creating Tables• Indexes: Specifies the type of data

indexing initially created.• Collation: Individual columns of

textual data may have a different collation setting than that of the server instance or the database.

• Compression: A table option that can control optional ROW or PAGE type data compression.

Page 7: Tables

Options when Creating TablesOptions when Creating Tables• Constraint: Table and column level

constraints may be specified.• Sparse: Individual columns may be

defined as SPARSE in order to conserve storage space for columns often containing a high percentage of NULL data.

Page 8: Tables

Data CompressionData Compression• SQL Server 2008 includes two new data

compression features for reducing the disk space requirements – Row Compression and Page Compression.

• Only one type of compression can be specified at a time on the same object.

• Compression can be used on both regular tables and nonclustered indexes.

• The space savings will, as with all forms of data compression, depend upon the nature of the data being compressed.

Page 9: Tables

Data CompressionData Compression• Data Compression is available only in

the Enterprise, Developer, or Evaluation Editions of SQL Server 2008.

Page 10: Tables

Data CompressionData Compression• A new stored procedure named

sp_estimate_data_compression_savings has been provided with SQL Server 2008 to provide estimated space savings without having to actually compress a table first.

• This stored procedure needs a table or index name and either ‘ROW’ or ‘PAGE’ as a compression method.

Page 11: Tables

Data CompressionData Compression• Both row based and page based

compression are enabled via either the CREATE TABLE, CREATE INDEX, ALTER TABLE, or ALTER INDEX commands. ALTER TABLE mytable REBUILD WITH (DATA_COMPRESSION = ROW);ALTER TABLE mytable REBUILD WITH (DATA_COMPRESSION = PAGE);

Page 12: Tables

Row CompressionRow Compression• Row Compression compresses all

columns in all rows in a table (or index).

• Involves compressing each row individually. Row compression is preferred over page compression when the data to be compressed has a higher percentage of unique data as compared to repetitive data.

Page 13: Tables

Page CompressionPage Compression• Page Compression also compresses all

columns in all rows in a table however the method of compression spans multiple rows thus involving an entire page of data.

• The purpose of page compression is to reduce the amount of redundant data stored in a page regardless of which row it is in.

• Thus page compression is preferred over row compression when the data on a page to be compressed has a higher percentage of repetitive data as compared to unique data.

Page 14: Tables

Sparse ColumnsSparse Columns• SQL Server 2008 includes a new

storage space savings feature known as sparse columns.

• Normally, even if a column often has NULL data, space must be allocated for the column.

• Using a sparse column option for a fixed length column potentially alters the fixed space allocation.

Page 15: Tables

Sparse ColumnsSparse Columns• When the majority of the rows in a table have

null data for a particular column, then that column is a probable candidate for use as a sparse column.

• Defining a column as sparse can actually increase the space used if the majority of the rows have data in the column.

• Sparse columns also require some additional processing overhead so like most things, using sparse columns is a tradeoff and you should use your best judgment depending upon the data.

Page 16: Tables

Sparse ColumnsSparse Columns• You require Enterprise, Developer, or

Evaluation Edition of SQL Server 2008 to use sparse columns.

Page 17: Tables

Partitioning TablesPartitioning Tables• Tables in SQL Server can range from small,

having only a single record, to huge, with millions of records.

• These large tables can be difficult for users to work with simply because of their size.

• To make them smaller without losing any data, you can partition your tables.

• Partitioning tables and views across multiple servers results in a federation of servers.

Page 18: Tables

Partition FunctionPartition Function• To partition this table, you first need to

decide on a partition column and a range of values for the column.

• In a table of order data, you probably have an order date column, which becomes an excellent candidate.

• Now you can use the partition column and range to create a partition function, which SQL Server uses to allocate the data across the partitions.

Page 19: Tables

Partition SchemePartition Scheme• After you figure out how to divide the

table, you next need to decide where to keep the partitioned data physically.

• You can keep archived data on one hard disk and current data on another disk by storing the partitions in separate filegroups, which can be assigned to different disks.

Page 20: Tables

SummarySummary• You learned you must sit down and plan before

you create tables. – You need to decide what the tables should

contain, making them as specific as possible.– Use Microsoft’s Visio or even pencil and paper.

• You also learned that tables consist of entities (which contain a specific type of data) and rows (an entity in the table that spans all columns).

• Each of the columns in the table has a specific data type that restricts the data it can hold.

Page 21: Tables

SummarySummary• You learned the mechanics of creating

tables in the database using both Transact-SQL and Management Studio.

• You learned the basics of data compression and implementing sparse columns. – Depending upon the data, either no

compression, row compression, or page compression should be chosen.

• You then learned you can spread the contents of a table over multiple resources, creating ultimately a federation of servers.

Page 22: Tables

Summary for Certification ExaminationSummary for Certification Examination• Partitioning tables allows you to break

a table into multiple pieces stored in separate files on multiple disks across multiple servers. – To partition a table, you need to select

a column, create a partition function, and then create a partition scheme.

– The partition function can be a LEFT or RIGHT range, so make sure you know how and why to choose.

Page 23: Tables

Summary for Certification ExaminationSummary for Certification Examination• A table collects records and

attributes (rows and columns) that SQL Server uses to store and organize data.


Recommended