Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 automatically increase ID column(please urgent)

Author  Topic 

sa_keles
Starting Member

9 Posts

Posted - 2005-12-17 : 21:41:33
i am trying to increase ID column automatically. i want ID column on my database to increase when i add new entry
thanks

SamC
White Water Yakist

3467 Posts

Posted - 2005-12-17 : 23:14:09
OK. Here's an example of an ID column:

CREATE TABLE MyTable (
MyID INT IDENTITY (1,1) NOT NULL UNIQUE,
ET CETERA...
)

Now what is your column definition like and how would you like it modified?
Go to Top of Page

sa_keles
Starting Member

9 Posts

Posted - 2005-12-18 : 09:18:19
thanks for your reply SamC i used on enterprise manager identity= yes(not for replication) identity seed=1 and identity increment=1 but while i am adding new entry it doesnt increase automatically. i am very new in sql (and english too so i cant explain what i think i hope you can understand :)) ) i am adding new antries on enterprise manager myTable right click return all rows (i will write a progrm for this )
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2005-12-18 : 09:44:41
EM has it's use, but you should also get experience in Query Analyzer - it has other features which out perform EM.

In EM, right-click on your table, select "all tasks", "generate sql script", "preview".

Copy the "create table" generated script, and post it back here.
Go to Top of Page

sa_keles
Starting Member

9 Posts

Posted - 2005-12-18 : 09:57:49
i think everything's normal. may be when i write a program for this work it increases automatically(could be?)

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tblAriza]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[tblAriza]
GO

CREATE TABLE [dbo].[tblAriza] (
[Ariza_ID] [int] IDENTITY (1, 1) NOT FOR REPLICATION NOT NULL ,
[Ariza_Makine_ID] [int] NOT NULL ,
[Ariza_Tarih] [datetime] NOT NULL ,
[Ariza_Durma_Süresi] [nvarchar] (50) COLLATE Latin1_General_CI_AS NULL ,
[Ariza_Bildiren] [nvarchar] (50) COLLATE Latin1_General_CI_AS NULL ,
[Ariza_Gideren] [nvarchar] (50) COLLATE Latin1_General_CI_AS NULL ,
[Ariza_Aciklama] [nvarchar] (250) COLLATE Latin1_General_CI_AS NULL
) ON [PRIMARY]
GO
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2005-12-18 : 10:23:03
I gotta run, but try doing an insert without using EM's grid editor...

In EM (or QA)...

INSERT INTO dbo.tblAriza (Ariza_Makine_ID, Ariza_Tarih, etcetera, ...)
SELECT values go here

Then take a look at the identity column. It's been known to work properly before
Go to Top of Page

sa_keles
Starting Member

9 Posts

Posted - 2005-12-18 : 12:36:01
in query analyzer i am writing this code

insert into dbo.tblAriza (Ariza_Makine_ID,Ariza_Tarih,Ariza_Durma_Suresi,Ariza_Bildiren,
Ariza_Gideren,Ariza_Aciklama) values (1,'12.12.2005','3 gün','ali','mehmet','fena bi arýza');

but it returns a warning

Server: Msg 208, Level 16, State 1, Line 1
Invalid object name 'tblAriza'.

what does it mean?
Go to Top of Page

sa_keles
Starting Member

9 Posts

Posted - 2005-12-18 : 12:45:48
may mydatabase be closed? how can i open a database in query analyzer? i am lookin help file but couldnt find yet
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2005-12-18 : 15:32:04
QA should show the DB you are working on in a drop-down window in the top toolbar.

If you aren't connected, try the menu: FILE, CONNECT and fill in the username and so on.

If you are working on a remote server, you might want to setup a local alias for that server / database using MS SQL "Client Services Utility". Should be in the same folder as QA and EM.

Sam
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2005-12-18 : 15:34:03
You can also insert a quick shortcut on your desktop to launch QA with login parameters. The shortcut properties should look like:

"C:\Program Files\Microsoft SQL Server\80\Tools\Binn\isqlw.exe" -S "IP address or (local)" -d databasename -U yourUsername -P yourpassword
Go to Top of Page

sa_keles
Starting Member

9 Posts

Posted - 2005-12-18 : 17:05:39
connection is ok but under localserver a lot of database (forexample:northwind, pubs,YAZILIM,DonemProjesi...) how can i specify one of them it could be the problem(could it be??) i am connecting but cant do anything else. it returns warning near table names may be i cant write true insert command is this use true?
insert into dbo.tblAriza (Ariza_Makine_ID,Ariza_Tarih,Ariza_Durma_Suresi,Ariza_Bildiren,
Ariza_Gideren,Ariza_Aciklama) values (1,'12.12.2005','3 gün','ali','mehmet','fena bi arýza');
i am writing this code in query analyzer. sql server on my computer not a remote server
Go to Top of Page

TonyTheDBA
Posting Yak Master

121 Posts

Posted - 2005-12-20 : 10:59:48
quote:
how can i specify one of them

You can specify the database either using the Drop down box or
USE DBName
GO
Select * from Employees
where DBName is the name of your database SO USE Northwind will change to the Northwind Database and then list the contents of the Employees Table


--
Regards
Tony The DBA
Go to Top of Page
   

- Advertisement -