Data types and Precedence of convert types
SQL Server associates columns, expressions, variables, and parameters with data types. Data types determine what kind of data can be stored in the field: Integers, characters, dates, money, binary strings, etc.
SQL Server supplies several built-in data types but you can also define custom types
Built-in data types are categorized as shown in the table below, also you can see the precedence of convert to other data type. I mean when an operator combines two expressions of different data types, the rules for data type precedence specify that the data type with the lower precedence is converted to the data type with the higher precedence.
SQL Server uses the following precedence order for data types:
- user-defined data types (highest)
- sql_varian t
- nvarchar (including nvarchar(max) )
- varchar (including varchar(max) )
- varbinary (including varbinary(max) )
- binary (lowest)
How, where, when you need to think in data storage? Well, this is the first step after you modeling your database and most companies do not think about it, I have saw companies with a large data into one disk or small data separated in the wrong way, but what is the best to do?
We have some best practices and you can read more about logical structures in SQL Server called filegroups in MSDN page. Every DBA needs to know to create and maintain filegroups because they are part of every SQL Server database. Filegroups affect the performance, maintenance, and security of your data and they are logical structures to group files together.
At a minimum, every SQL Server database has two operating system files: a data file and a log file. Data files contain data and objects such as tables, indexes, stored procedures, and views. Log files contain the information that is required to recover all transactions in the database. Data files can be grouped together in filegroups for allocation and administration purposes.
Filegroups can be created when the database is first created or created later when more files are added to the database. However, you cannot move files to a different filegroup after the files have been added to the database.
A file cannot be a member of more than one filegroup. Tables, indexes, and large object (LOB) data can be associated with a specific filegroup. This means that all their pages are allocated from the files in that filegroup.
Why use filegroups?
- you have one or more objects tha have heavy read/write activity
- you’ve already tuned through indexes and query writing
- you need a performance boost
- you have additional storage you can utilize to separate the objects
- you want to separate tha data so administration tasks such as backups take less time
- you have a large database (>1TB)
- disaster and recovery
- separate data and log files onto separate disks
- separate tempdb onto its own disk
- at least two filegroups – primary and one user-defined (default)
- files in a filegroup should be equally sized for equal proportion of writes
- use filegroups to isolate objects with heavy read and write activity from each other