Sometimes the simplest of t-sql approaches are often overlooked. Once such instance I came across recently, was a developer trying to insert default values in a SQL Server Table. Here’s a simple way to insert Default Values in a SQL Server table
CREATE TABLE #Employees
(
ID int Identity(1,1) PRIMARY KEY,
EName varchar(50),
Designation varchar(50),
ManagerID int NULL
)
INSERT INTO #Employees DEFAULT VALUES;
SELECT * FROM #Employees
Observe how the DEFAULT VALUES option of the INSERT statement is used to add rows without supplying explicit values. Simple!
OUTPUT

About The Author
Suprotim Agarwal, MCSD, MCAD, MCDBA, MCSE, is the founder of
DotNetCurry,
DNC Magazine for Developers,
SQLServerCurry and
DevCurry. He has also authored a couple of books
51 Recipes using jQuery with ASP.NET Controls and a new one recently at
The Absolutely Awesome jQuery CookBook.
Suprotim has received the prestigous Microsoft MVP award for nine times in a row now. In a professional capacity, he is the CEO of A2Z Knowledge Visuals Pvt Ltd, a digital group that represents premium web sites and digital publications comprising of Professional web, windows, mobile and cloud developers, technical managers, and architects.
Get in touch with him on Twitter @suprotimagarwal, LinkedIn or befriend him on Facebook
No comments:
Post a Comment