CIS 612 Lab Assignment 2 Subject: Modern Database Programming and Big Data Processing Instructor: Dr. Sunnie S. Chung Software’s Used: • Microsoft SQL Server 2012 • SQL Server Management Studio • Microsoft Visual Studio 2012 Subject: Using UDT, UDF and Table Function
16
Embed
CIS 612 Lab Assignment 2cis.csuohio.edu/~sschung/cis612/Lab2_SolutionAnkur.pdf · CIS 612 Lab Assignment 2 Subject: Modern Database Programming and Big Data Processing Instructor:
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
CIS 612 Lab Assignment 2
Subject: Modern Database Programming and Big Data Processing
Instructor: Dr. Sunnie S. Chung
Software’s Used:
• Microsoft SQL Server 2012
• SQL Server Management Studio
• Microsoft Visual Studio 2012
Subject: Using UDT, UDF and Table Function
Part 1:
1. Creating User Defined Type GeoPoint, Table Functions Dept_GeoLocations
using System;
using System.Data;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server; using System.Text;
DROP TABLE TablePoints CREATE TABLE dbo.TablePoints (
ID int IDENTITY(1,1) PRIMARY KEY,
Pnt PointType) INSERT INTO dbo.TablePoints (Pnt) VALUES (CONVERT(PointType, '3:4'))
INSERT INTO dbo.TablePoints (Pnt) VALUES (CONVERT(PointType, '-1:5'))
INSERT INTO dbo.TablePoints (Pnt) VALUES (CAST ('1:99' AS PointType))
SELECT ID, Pnt.ToString() as StringPoint,
Pnt.X as X,
Pnt.Y as Y FROM dbo.TablePoints
Output:
Test Script 2:
CREATE TABLE Locations (grid_location dbo.PointType) INSERT INTO Locations (grid_location) VALUES ('3:2') INSERT INTO Locations (grid_location) VALUES ('-1:1') INSERT INTO Locations (grid_location) VALUES ('-1:-1') INSERT INTO Locations (grid_location) VALUES ('-8:-9') INSERT INTO Locations (grid_location) VALUES ('4:-9') ------------------------------------------------------------------- -- -- view the data -- ------------------------------------------------------------------- SELECT * FROM dbo.Locations SELECT grid_location.X AS "X", grid_location.Y AS "Y", grid_location.ToString() AS "Point" FROM Locations ------------------------------------------------------------------- -- -- update some rows -------------------------------------------------------------------- UPDATE dbo.Locations SET grid_location.X = 5 WHERE grid_location.Y < 0 SELECT grid_location.X AS "X", grid_location.Y AS "Y", grid_location.ToString() AS "Point" FROM Locations;
Output:
2. Create Table Function that returns a table Dept_GeoLocations:
Table Function:
using System;
using System.Linq; using System.Text;
using System.Threading.Tasks;
using System.Collections; using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
public class GeoLocation
{ public SqlInt32 Dnumber;
public SqlString Dlocation;
public SqlString Location;
public GeoLocation(SqlInt32 Dnum, SqlString Dloc, SqlString Geoloc)