How to define a parameter to insert Date in SQL Server?
I mean I want to create a table in SQL server which contain a column for birth date of customer so I want to know which parameter I must use in SQL server to distinguish that I want to insert date in record. Please guide me.


Vikrant MoreRank #1,157 · 1.6K reputationPosted Feb 17, 2015, 5:16 AM EST
Vikrant MoreRank #1,157 · 1.6K reputationPosted Feb 16, 2015, 6:36 AM EST
Lets see below create table statement,
CREATE TABLE CUSTOMER
(
CustomerID INT IDENTITY(1,1),
FirstName VARCHAR(100),
LastName VARCHAR(100),
DateOfBirth DATE
)
INSERT INTO CUSTOMER(FirstName,LastName,DateOfBirth) VALUES('Vikrant','More','1984-10-11')
Jignesh TrivediRank #16 · 50.3K reputationPosted Feb 16, 2015, 6:31 PM EST
Identity is used for auto increment value so no need to pass the value in this column SQL server automatic add incremental number in this column.
If you are user of SQL server 2008 and above so you can use DATE datatype to define birth date because in birth date we don't required time.
hope this will help you.
Jignesh TrivediRank #16 · 50.3K reputationPosted Feb 16, 2015, 7:34 PM EST
Hi,
It is not default value...
we cannot update the value of identity column.
Please refer below link to know more about identity column
https://technet.microsoft.com/en-us/library/aa933196(v=sql.80).aspx
http://www.sqlteam.com/article/understanding-identity-columns
hope this will help you.
Saumitr Sharma13 reputationPosted Feb 16, 2015, 8:05 PM EST
cmd.CommandText = "INSERT INTO person (birthdate) VALUES(@date)"; cmd.Parameters.Add(new SqlParameter("@date", dateTimePicker.Value.Date)); //con is sql connection con.Open(); cmd.ExecuteNonQuery(); con.Close(); Either change the datatype to datetime and or pass only Date value to insert.Jignesh TrivediRank #16 · 50.3K reputationPosted Feb 17, 2015, 6:15 PM EST
Hi,
You can apply Identity column on the column which has numeric data type like int, bigint etc....
and only one identity column possible with one table
If you are user of SQL 2012 that you can also use sequence please refer my article.
http://www.c-sharpcorner.com/UploadFile/ff2f08/sequence-in-sql-server-2012/
hope this will help you.
Joe WilsonRank #631 · 3.8K reputationPosted Feb 16, 2015, 7:25 AM EST
CustomerID INT and I want to use male and female in gender column in order to just choose one of male or female instead of typing one of them.
Joe WilsonRank #631 · 3.8K reputationPosted Feb 16, 2015, 7:28 PM EST
Joe WilsonRank #631 · 3.8K reputationPosted Feb 17, 2015, 3:12 AM EST
Joe WilsonRank #631 · 3.8K reputationPosted Feb 17, 2015, 3:13 AM EST
Joe WilsonRank #631 · 3.8K reputationPosted Feb 17, 2015, 6:58 AM EST
Joe WilsonRank #631 · 3.8K reputationPosted Feb 17, 2015, 7:13 PM EST