1 / 23

Tables

Tables. Lesson 6. Skills Matrix. Tables. Tables store data. Tables are relational They store data organized as row and columns.

ossie
Download Presentation

Tables

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Tables Lesson 6

  2. Skills Matrix

  3. Tables • 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).

  4. Creating Tables • Open SQL Server Management Studio. In Object Explorer, expand ServerDatabasesMSSQL_Training. • Right-click the Tablesicon and select New Table to open the Table Designer. • Tables are often created using SQL scripts containing CREATE TABLE commands.

  5. Options 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.

  6. Options 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.

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

  8. Data Compression • Data Compression is available only in the Enterprise, Developer, or Evaluation Editions of SQL Server 2008.

  9. Data 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.

  10. Data 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);

  11. Row 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.

  12. Page 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.

  13. Sparse 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.

  14. Sparse 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.

  15. Sparse Columns • You require Enterprise, Developer, or Evaluation Edition of SQL Server 2008 to use sparse columns.

  16. Partitioning 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.

  17. Partition 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.

  18. Partition 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.

  19. Summary • 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.

  20. Summary • 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.

  21. Summary 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.

  22. Summary for Certification Examination • A table collects records and attributes (rows and columns) that SQL Server uses to store and organize data.

More Related