Académique Documents
Professionnel Documents
Culture Documents
Objectives
Use Visual Studio for GUI based interactive access to a Microsoft SQL Server database.
Use sqlcmd for command line interactive access to a Microsoft SQL Server database. Using either Visual Studio or sqlcmd to:
Create and delete tables. Insert new rows into tables. Modify table definitions. Modify existing rows. Retrieve and display table data.
CoE Resources
We all have accounts, with a single database each, on a Microsoft SQL Server on the CoE network:
scorpius.eng.usf.edu
A VPN connection is required for your home computer or wireless laptop to access scorpius.
This is the same machine that we use as a web server. Different server software. Different user accounts.
Be sure to use the username and password that you have been given for the SQL Server
The database server version on scorpius is too old! We have to use Visual Studio 2008.
If you don't have Visual Studio 2008 on your computer, you can get a free 90 day trial from Microsoft.
http://www.microsoft.com/en-us/download/details.aspx?id=3713
Can't be installed directly. Must use Virtual CD program or burn a real CD See http://msdn.microsoft.com/en-us/subscriptions/aa948864.aspx
OR
https://www.dreamspark.com/
You will see this the first time you add a data connection.
Click here
10
Adding a Table
Define the table in Visual Studio. Download the table as a CSV file. Open the spreadsheet in Excel. Copy the spreadsheet data in Excel. Paste the data into the database table in Visual Studio. Modify the table definition to add a unique ID column.
11
Adding a Table
13
Adding a Table
14
Data Types
n = max number chars n = number chars p = total number of digits s = number decimal places
Many more!
15
16
Save
17
18
20
Populating a Table
Download file Addresses.csv from the Downloads area of the class web site:
http://www.cse.usf.edu/~turnerr/Web_Application_Design/Downloads/Addresses.csv
21
Excel Worksheet
22
We will use the contents of this Excel worksheet to populate the Address table in the database. Click inside the worksheet, then press Ctrl-A to select all.
Press Ctrl-V to paste the clipboard into the table. (This may take a while to complete.)
24
Setting an ID Field
Unique identifier Normally an Identity column. Value set by server as each row is added
25
Add Column ID
27
29
Save
30
End of Section 31
http://msdn.microsoft.com/en-us/library/ms162773.aspx
Connect to a Database Server Enter SQL commands on the command line. Results output to the console.
32
http://www.microsoft.com/en-us/download/details.aspx?id=8824
33
The following slides demonstrate SQL commands using the sqlcmd program. Remember SQL is used everywhere we interact with a database server:
34
Using sqlcmd
The Server
35
36
37
Wildcard Selection
Find all addresses with last name beginning with S
38
Wildcard Selection
All addresses with last name containing an s
39
Case Sensitivity
SQL commands and keywords are not case sensitive. Data is case sensitive
40
Case Sensitivity
41
Zip Codes
43
Counting Rows
How many addresses are there with zip code 33707?
44
Updating Records
45
46
Deleting a Record
47
We can also use Visual Studio to issue arbitrary SQL commands to the server. On the Data menu select New Query
48
49
Click here
50
52
Learning SQL
54