Reputation: 3937
I'm trying to understand how to populate Tables and have been given some code by my professor. I can't tell why these two statements are different in their Syntax:
Q1:
Insert into SecurityType (SecurityTypeCode, SecurityTypeDesc)
Values ('STO', 'Stock');
INSERT INTO [Country] ([CountryId], [CountryCode], [CountryDesc]) VALUES (-1, N'NOT SPECIFIED', N'Not Specified')
That is after looking at the two statements above, can we write the first statement as
Insert into SecurityType ([SecurityTypeCode], [SecurityTypeDesc])
Values ('STO', 'Stock');
Q2: My professor says "You need to set Idenitity insert ON in order to insert a value into an identity column". I'm unclear as to what an "identity column" is.
Thanks
Upvotes: 0
Views: 43
Reputation: 13425
1) Column names can be wrapped in brackets, this is done if your column name is a reserved key word or your column name has spaces.
So you can have the brackets around the column names and it is same as first statement.
2) Identity column values automatically generated and you use this syntax to create such a column
CREATE TABLE Employee
(
id int IDENTITY(1,1)
SQL server doesn't allow you to insert a value for this identity column, in case you want to insert a default value or some values , you can set identity insert ON.
Upvotes: 0