Download presentation
Presentation is loading. Please wait.
Published byKristian Elijah Lamb Modified over 9 years ago
1
Databases in Visual Studio
2
Database in VisualStudio An MS SQL database are built in Visual studio The Name can be something like ”(localdb)\Projects” or ””(localdb)\v11.0” Visible through the view -> SQL Server Object Explorer From here you can Create new database instances (e.g. new databases) Within a database you can create tables, triggers, constraints (e.g. foreign keys) etc. Within a table you can insert, delete, update rows OR query information (select) using SQL Alternative you view data and change data from ‘view data’
3
Three ways to create tables Create a database in SQL server Object Explorer 1.‘right click’ and use the design tool in Visual Studio 2.Make a SQL script to create the table ”CREATE TABLE table-name ( column-name type …, ….)” Create a database inside the project 3.Entity Framework e.g. include a database into the project “add -> new item -> data -> ADO.NET Entity Data Model”
4
Create database in SQL Server Object Explorer Open SQL Server Object Explorer Open (localdb)\projects OR (localdb)\v11.0 Open Database ‘right click’ -> add new database … Choose a name
5
Create tables using SQL For details see http://www.w3schools.com/sql/default.asphttp://www.w3schools.com/sql/default.asp Short: CREATE TABLE Persons ( PersonID int NOT NULL PRIMARY KEY, LastName varchar(255) NOT NULL, FirstName varchar(255), Address varchar(255), City varchar(255) );
6
Create tables using MS SQL gui design For details see: http://msdn.microsoft.com/en-us/library/hh272695(v=vs.103).aspxhttp://msdn.microsoft.com/en-us/library/hh272695(v=vs.103).aspx (1) Right click -> Add new table (2) Change name of Table (3) Add columns (4) Update database
7
Create Database inside the project Create a normal project (form, console, wpf, class-library) ‘right click’ on project add -> new item -> data-> service-based database … name it
8
Create tables In the project : add -> new item -> data -> ADO.NET Entity Data Model … name it choose ‘empty model’ In diagram ‘right click’ -> add new -> entity (=table) Fill out entity name (= table name) Fill out property for primary key (default id:int) Add more properties/columns one by one – remember type ‘right click’ generate database from model – pick (connect to ) your database
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.