Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
CREATE TABLE Persons
(
PersonID int,
LastName varchar(255),
FirstName varchar(255)
)

INSERT INTO Persons(PersonID , LastName, FirstName )
VALUES( 1, Maria , Di );
Posted
Comments
Thanks7872 17-Oct-14 1:33am    
Why you think it is not? Run it. If it gives error than its wrong.

Character field need to be in quotes as below

INSERT INTO Persons(PersonID , LastName, FirstName )
VALUES( 1, 'Maria' , 'Di' );
 
Share this answer
 
Comments
aarif moh shaikh 17-Oct-14 0:07am    
yes... Right
You can also use below

XML
INSERT INTO Persons
select  1, 'Maria' , 'Di'

Although giving columns names is good practice.

INSERT INTO Persons(PersonID , LastName, FirstName )
select  1, 'Maria' , 'Di' 


If you are calling this query from front end then do wrap it within a stored procedure other wise it will open to SQL Injections.
 
Share this answer
 
If you think your code may have some errors..??

then.
C#
1> Run the code first
2> Get the Eroor
3> try to understand the Error yourself
4> try to find the solution for the error which you are getting
5>if not figureout then try to find it in google
6>Lastly ask here or any other website to find the solution.
 
Share this answer
 
INSERT INTO Persons(PersonID , LastName, FirstName )VALUES( 1, 'Maria' , 'Di' );

when we insert or update string/Character value to db ,value can be given within single quotes

Regards
Ramesh
 
Share this answer
 
Comments
aarif moh shaikh 17-Oct-14 4:44am    
This answer Already given by RossMW.. than why?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900