Saturday, June 8, 2013

T-SQL Notes

SELECT list_of_columns_required
FROM list_of_tables_or_views_that_act_as_source_of_data
WHERE list_of_conditions_or_filter
ORDER BY sort_order_columns;

http://msftdbprodsamples.codeplex.com/ --- sample database download for SQL Server products

To connect to specific database in an SQL Server Instance:
USE [AdventureWorks2012]
GO

One SQL Server Instance, can have many databases used by one or more different applications.

select * from [AdventureWorks2012].[HumanResources].[Employee]
select * from AdventureWorks2012.HumanResources.Employee

We can do:


USE [AdventureWorks2012]
GO
SELECT * from HumanResources.Employee


The advantage with high-lighted approach: The code can be run against a different database, as long as the schema exists.

Say we can have [MYSTARTUP] database which has HumanResources schema and the schema contains Employee table.

SELECT
 BusinessEntityID
 ,NationalIDNumber
 ,LoginID
FROM
[HumanResources].[Employee]


In the above HumanResources is Schema. A schema contains the object, and that schema is then owned by a user. Because users own a schema, and the schema contains the object, you can change the owner of the schema without having to modify object ownership.




No comments:

Post a Comment