Friday, 17 March 2017

Basic SQL

CREATE TABLE [dbo].[Country] (
    [CountryId]     INT           IDENTITY (1, 1) NOT NULL,
    [Name]    VARCHAR (50)  NOT NULL,  
    PRIMARY KEY CLUSTERED ([CountryId] ASC)
);

CREATE TABLE [dbo].[State] (
    [StateId]     INT           IDENTITY (1, 1) NOT NULL,
[CountryId] int,
    [Name] int NOT NULL,  
    PRIMARY KEY CLUSTERED ([StateId] ASC),
    FOREIGN KEY (CountryId) REFERENCES Country(CountryId)
);