How to Change the Collation of a SQL Server Database using T-SQL

This is a quick article to demonstrate how to use Transact-SQL to change the collation of a database in SQL Server.

Here’s the basic code:

USE master;  
GO
 
ALTER DATABASE Solutions  
COLLATE French_CI_AS ;  
GO 

This first changes to the master database, then we use the ALTER DATABASE statement to change the collation of the Solutions database to French_CI_AS collation.
Continue reading

How to Create a Table in SQL Server using a Query

To create a table in SQL Server using a query:

  1. In the SQL Server Management Studio, click the New Query button on the toolbar
  2. Type or paste a CREATE TABLE script (example below)
  3. Click the ! Execute button on the toolbar

Here’s an example:

Screenshot of SSMS with the New Query button highlighted.
Clicking the “New Query” button on the SSMS toolbar opens a new query. Clicking “Execute” runs the query.

Continue reading

What is a View?

In the world of databases, a view is a query that’s stored on a database.

The term can also be used to refer to the result set of a stored query.

To create a view, you write a query, then save it as a view.

To run a view, you query it, just like you’d query a table. The difference is that, the view itself is a query. So when you query the view, you’re effectively querying a query.  This enables you to save complex queries as views, then run simple queries against those views.

Continue reading