Yes, you can do that.
For inserting, you need to first insert into the Main Table/Primary table, then in the Foreign Key Table.
So, in your example, for State, first you need to insert in State Table and then get the inserted ID and insert into the City Table.
To get the most recently inserted ID, you can use
@@IDENTITY
or
SCOPE_IDENTITY()
. Refer one example -
Re: How to add values of primary key column into foreign key column of other table?[
^]
While inserting into main Tables, if you want that ID should be Auto-Incremented, then you need to set the "
Is Identity" property to "
Yes" and "
Identity Increment" property to the number you want to increment to.
Refer -
Auto increment primary key in SQL Server Management Studio 2012[
^]