How to Insert Microsoft SQL
Microsoft SQL Server offers fast query delivery and reliable availability for businesses of all sizes. Inserting your data into a database can be much more versatile and efficient than storing it offline in a document or spreadsheet. The Microsoft SQL Server uses the Transact-SQL, or T-SQL, extension for compatibility between various user interfaces. The INSERT command behaves the same way as other SQL servers, and you can add database rows with variables from other tables or with a SQL SELECT statement.
Click the Start button and launch “Microsoft SQL Server.” Click the “Server Name” menu and click the server to which you’d like to connect. Click “Connect” to open the Object Explorer.
Right-click the server’s name in the database tree on the left side of the window. Click “New Query” to open a command-line window for entering SQL statements.
Add a line similar to the following to specify the table into which you’re inserting a record as well as the names of the columns you’re inserting:
INSERT INTO client_accounts( client_number, last_name, first_name, address)
Specify the column values of the row you’re inserting with a VALUES statement like the following:
VALUES( 12345, ‘Jones’, ‘Melissa’, ‘543 W 21st Street’) GO
Execute the statement with the GO keyword, similar to a terminal semicolon when working with other database servers.
Use the SELECT keyword instead of VALUES to insert columns from another table in the database. Place the column name to match inside a pair of single quotes. For example, type the following command:
INSERT INTO client_accounts SELECT ‘client_number’ 12345 FROM other_table_name GO
Replace “other_table_name” with the name of the table to select from.
- Use the BEGIN TRANSACTION command to create a restore point for any changes you make to a database. For example, type the following:
- BEGIN TRANSACTION insert_transaction
- After making your changes, use either the ROLLBACK or COMMIT keyword to save or undo the changes, as in the following code:
- ROLLBACK TRANSACTION insert_transaction
David Wayne has been writing since 2010, with technology columns appearing in several regional newspapers in Texas. Wayne graduated from the University of Houston in 2005, earning a Bachelor of Arts in communications.