'How to define a geography column in a table with different columns type at SQL database
Consider I have a table with different columns types:
CREATE TABLE [RentedHome]
(
[HomeID] INT NOT NULL PRIMARY KEY CLUSTERED,
[Address] CHAR (255) NOT NULL CHECK (LEN(Address) >= 2),
[Landlord] CHAR (100) NOT NULL CHECK (LEN(Landlord) >= 2),
[Tenant] CHAR (100) NOT NULL CHECK (LEN(Landlord) >= 2),
)
I want to add the Geography column to the mentioned table, how should I define the column (I want to insert just a geography-point for each home):
[Location] GEO (yyy)
Thanks
Solution 1:[1]
Done!
CREATE TABLE [RentedHome]
(
[HomeID] INT NOT NULL PRIMARY KEY CLUSTERED,
[Address] CHAR (255) NOT NULL CHECK (LEN(Address) >= 2),
[Landlord] CHAR (100) NOT NULL CHECK (LEN(Landlord) >= 2),
[GeoLocation] geography,
[Tenant] CHAR (100) NOT NULL CHECK (LEN(Tenant) >= 2),
)
inserting example:
INSERT INTO [RentedHome]
VALUES (1, '177 Huntington Ave #1010, Boston, MA 02115, United States', 'Northeastern University', geography::Point(42.34497193099456, -71.08252116132054, 4326), 'Network Lab')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | amin |
