December 16, 2009 at 9:41 pm
create table Empdata(empid int, Empname varchar(3), empsalary decimal(7,3))
insert into Empdata values(1001,'LuckyAmerican',101)
This will give an error as follows:
Msg 2714, Level 16, State 6, Line 1
There is already an object named 'Empdata' in the database.
I don't want any error and the only 'Luc' to be inserted or whatever but no error should be thrown.
December 16, 2009 at 10:01 pm
Hi,
The error tells you that the table already in the database, you just drop the table and insert the record.
And the table data type for the column Empname is only three characters; you may increase the data type length and insert the record.
December 17, 2009 at 9:35 am
You would test for the existence of the table before creating the table. Like this:
IF OBJECT_ID('Empdata') IS NULL
BEGIN
create table Empdata
(
empid int,
Empname varchar(3),
empsalary decimal(7, 3)
)
END
insert INTO Empdata
values
(
1001,
'LuckyAmerican',
101)
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply