1 / 8

Databases in Visual Studio

Databases in Visual Studio. 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

glain
Download Presentation

Databases in Visual Studio

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 • ‘right click’ and use the design tool in Visual Studio • Make a SQL script to create the table ”CREATE TABLE table-name ( column-name type …, ….)” Createa database inside the project • 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. Createtablesusing SQL • For detailsseehttp://www.w3schools.com/sql/default.asp • Short: CREATE TABLE Persons(PersonIDint NOT NULL PRIMARY KEY,LastNamevarchar(255) NOT NULL,FirstNamevarchar(255),Address varchar(255),City varchar(255));

  6. Createtablesusing MS SQL gui design • For detailssee: http://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 projectadd -> new item -> data-> service-based database … name it

  8. Createtables • In the project :add -> new item -> data -> ADO.NET Entity Data Model … name itchoose ‘empty model’ • In diagram ‘right click’ -> add new -> entity (=table) • Fill out entityname (= tablename) • Fill out property for primarykey (default id:int) • Add more properties/columns one by one – remember type • ‘right click’ generate database from model – pick (connect to ) your database

More Related