MS SQL Notes
Notes about MS SQL.
SQL Server Developer is available as a full-featured free edition for development and testing.
SQL Server Management Studio (SSMS)
SQL Server Management Studio (SSMS) - Use SQL Server Management Studio (SSMS) to query, design, and manage your databases and data warehouses, wherever they are - on your local computer, or in the cloud. SMS is free! Download
Open SSMS (Microsoft SQL Server Tools / Microsoft SQL Server Management Studio 17)
The first time you run SSMS, the Connect to Server window opens. If it doesn't open, you can open it manually by selecting Object Explorer > Connect > Database Engine.
Object Explorer > Connect > Database Engine
The format of the name is HOSTNAME\INSTANCENAME. If you see only the host name, then you've installed the default instance and your instance name is MSSQLSERVER. When you connect to a default instance, the host name is all you need to enter to connect to your SQL server.
Use Windows Authentication.
How to Connect to MS SQL Using C#
Understanding "login failed" (Error 18456) error messages in SQL Server 2005:
Walkthroughs for Connecting Windows Forms Applications to Data
In Visual Studio / View / SQL Server Object Explorer
YouTube Video Tutorial on How to Connect to MS SQL Server Using C# in Visual Studio 2017
C# Tutorial 25 C# Databases:
In Visual Studio: View / Server Explorer
Connection string can be put in App.config file in the appSettings tag.
<add key="provider" value="System.Data.SqlClient" />
<add key="connectionString1" value=""/>
To Get Connection String Using Visual Studio
In VisualStudio 2015:
Server Explorer / Data Connections
Data Source=localhost;Integrated Security=True
Libraries That Are Important
C# Database Programming for Beginners Part 1
Part 2 Querying the Database with SQL
Part 3 Database Connection and Populating List Box
Add New Data Source
Visual Studio / Data Sources tab / Data Sources window / Add New Data Source
Project / Add Reference / to System.Configuration
Add a Database to a Project
View / Solution Explorer / Right Click on Project / Add / New Item / Service-Based Database
This will then appear as a .mdf file in the Solution Explorer and also in the Server Explorer.
In Server, right click on Tables and go to Add New Table.
Types of SQL Files
SQL Server databases use two files - an MDF file, known as the primary database file, which contains the schema and data, and a LDF file, which contains the logs. See wikipedia. A database may also use secondary database file, which normally uses a .ndf extension.
Set Field as Primary Key
Click on Field Name / Properties Window / Table Designer / Identity Specification / (Is Identity) / Set to True
This means it will increment the value by 1 each time you insert a new record.
nvarchar(MAX) - Like a free form text field.
In Server Explorer / Tables / Add Table / Then Add Your Fields / Hit the Update button.
It's function is to relate other tables together.
You can right click on Foreign Key in Table Design window to add new Foreign Key. Visual Basic will show the T-SQL for this.
Schemas and Object Names
Schemas are namespaces for database objects.
When referring to a table, best practice is to include schema name:
Transact-SQL Data Types
Types of SQL Joins
Ultimate List of 40 Important SQL Queries from ByteScout
All Content ©2018 WebRef.eu