Tutorial by Examples

CREATE TABLE MyTableName ( Id INT, MyColumnName NVARCHAR(1000) ) GO INSERT INTO MyTableName (Id, MyColumnName) VALUES (1, N'Hello World!') GO
To do an insert on specific columns (as opposed to all of them) you must specify the columns you want to update. INSERT INTO USERS (FIRST_NAME, LAST_NAME) VALUES ('Stephen', 'Jiang'); This will only work if the columns that you did not list are nullable, identity, timestamp data type or compute...
To insert multiple rows of data in SQL Server 2008 or later: INSERT INTO USERS VALUES (2, 'Michael', 'Blythe'), (3, 'Linda', 'Mitchell'), (4, 'Jillian', 'Carson'), (5, 'Garrett', 'Vargas'); To insert multiple rows of data in earlier versions of SQL Server, use "UNION ALL" like so: ...
A single row of data can be inserted in two ways: INSERT INTO USERS(Id, FirstName, LastName) VALUES (1, 'Mike', 'Jones'); Or INSERT INTO USERS VALUES (1, 'Mike', 'Jones'); Note that the second insert statement only allows the values in exactly the same order as the table columns whereas in...
When INSERTing, you can use OUTPUT INSERTED.ColumnName to get values from the newly inserted row, for example the newly generated Id - useful if you have an IDENTITY column or any sort of default or calculated value. When programatically calling this (e.g., from ADO.net) you would treat it as a nor...
To insert data retrieved from SQL query (single or multiple rows) INSERT INTO Table_name (FirstName, LastName, Position) SELECT FirstName, LastName, 'student' FROM Another_table_name Note, 'student' in SELECT is a string constant that will be inserted in each row. If required, you can select a...

Page 1 of 1