Newby - AUTOINCREMENT Problem.
Nov 5, 2005
Hi,
I'm enclosed a snippet of test code which highlights my problem. The Stored
procedure insertValue should insert text into the parent, then insert other
text into the child table but the 2 tables should auto increment in sync
(i.e. so that they both end up with the same id numbers). I've tried taking
the auto increment out of the child table but then I don't know how to get
the right parent id into the child table.
Any advice appreciated - this is my first database, so I'm just in the
learning process really. Code follows:
CREATE TABLE Parent
(id INTEGER DEFAULT AUTOINCREMENT,
parenttext VARCHAR(16),
PRIMARY KEY (id))!
CREATE TABLE Child
(childID INTEGER INTEGER DEFAULT AUTOINCREMENT,
childtext VARCHAR(16),
FOREIGN KEY (childid) REFERENCES Parent(id),
PRIMARY KEY (childID))!
CREATE PROCEDURE insertValues(in p VARCHAR(16), in c VARCHAR(16))
BEGIN
insert into parent (parenttext) values (p);
insert into child (childtext) values (c);
END!
call insertValues('from parent', 'from child')!
select * from parent, child where parent.id = child.childid!
View 5 Replies
ADVERTISEMENT
Feb 25, 2008
to create a code.
Hi everyone,
I have SQL SERVER 2005 on my desktop and i need to run queries from remote machines on my SQL SERVER.
I thought it would be a good i idea to create a web page on my machine to where remote users can contact and activate SQL QUERIES.
My question is very simple and i wonder i a simple answer is available:
How do i run SQL queries whereby ASP code ?
How do i make a connection between a web page (.asp code) and a SQL sever ?
If the answer is complicated as i'm afraid it is, could any one provide me a link for a tutorial dealing with the above issues ?
Thanks a lot !
View 2 Replies
View Related
Jul 10, 2006
Hi,I am trying to set up a DTS Package to transfer data from a remoteMySQL server to a local MS SQL database. The source tables will remainstatic as will the destination however I only want to copy down datathat does not already exist in the local database.I have two different methods of which to identify the new rows, on sometables it is by a unique ID thus in TSQL I would say WHERE ID x.Other tables are by date where I would want to do something like WHERECreateDate >= GetDate()-1How would I go about performing such clauses using DTS?ThanksMike
View 2 Replies
View Related
Nov 14, 2006
I'm attempting to use a JOIN for the first time and I'm getting about 94,000 rows returned when I should only be getting about 270. Something must not be unique (possible DSN) but I can't figure out why the join is not working. I know it must be difficult to determine the problem without actually seeing the tables but could somebody with a lot of SQL experience spot any glaring problems with this query? Thanks!
SELECT DS.DSNName AS DSN,
S.ServerName AS WebServer,
DBs.DBName,
A.ServerName AS SQLServer
FROM DSNs DS,
Servers S,
DBs,
DSNs LEFT OUTER JOIN Servers A
ON DSNs.SQLServerID = S.ServerID
WHERE DBs.Status = 1
AND DS.WebserverID = S.ServerID
AND DBs.DBID = DS.DBID
ORDER BY DSN
View 3 Replies
View Related
Apr 20, 2008
This has all the earmarks of a procedural error on my part. I have it occuring on two computers with the same sequence and exceptions and with clean databases. Note: The code is from Doug Lowe's ASP.NET 2.0 Everyday Apps For Dummies 2006 loaded from the CD. The database is generate from a script provided by the author. I will paste it in at the end.
View 1 Replies
View Related
Oct 28, 2005
This Q is so easy I can't find the answer anywhere!
Why is SQL Server called 'Server' ? I understand it is a lot more capable and robust than Access but where does 'server' come into it.
I currently use ASP and Access for dynamic websites but it is time to move up a notch.
Do I just buy SQL Server, make a database, upload it to the same place as before and hey presto?
can I run lots of websites (on different domains and servers) from databases created with my single license standard edition?
Thanks
M
View 5 Replies
View Related
Jan 4, 2008
Hello All,
I'm hoping you all can provide me with a little advice? I just landed my first DBA position with a company that runs different versions of SQL Server (7.0, 2000, 2005) on many different boxes. The databases I will be managing are in the 10-30TB ranges. Mostly the databases are for OLAP access by the company’s customers. I will need to bring myself up to speed on everything because there is no DBA at the company to transfer information.
Can anyone provide any advise on how I should approach this task of learning my position and/or useful links to resources? Thank you in advance!
~Sean
View 20 Replies
View Related
Jul 20, 2005
I'm working on a website remotely through a VPN and my client uses SQLServer. There's a requirement for a database and my client uses SQLServer 2000.Is it possible to administer this database remotely, just like I dowith MySQL/PHP MyAdmin?Please elaborate.Thanks,Marjorie
View 2 Replies
View Related
Apr 13, 2008
I imagine a data-retrieval scenario where data destined for several different tables are collected and initially placed into one 'collector' table (say, ALLDATA); a stored procedure then kicks in and passes the records to individual destinations. For example, I might want to have data for two persons, Ann and Betty, come in and be routed to table_ann and table_betty respectively, with the correspondence stored in table LOOKUP:
id output_table
Ann table_ann
Betty table_betty
How could this be implemented? Perhaps with some kind of loop over the rows of LOOKUP, with table name retrieved and entered into a (EXEC-written?) query
insert into <table_name>
from alldata
where id in (select distinct id
from lookup
where output_table = <table_name>)
But how could one iterate over the list of table names? (These could be placed in table, of course, and the question become 'how could one iterate over a table's rows?')
I hope that this is an easy question for SQL Server pros, and will be grateful for a brief pointer/code snippet. (I may have given more background then necessary, but perhaps there are better solutions available there as well?)
Thanks a lot!
View 1 Replies
View Related
Nov 15, 2006
Im not sure how to explain this or if this is the correct forum but here it goes.
I have created a report from a view that gives me court hearing dates on a defendent. When I run the report/view I get two different dates for the person such as, 12/14/2006 and 12/15/2006. How can I get it to show only the later date (12/15/2006)? I pull information from a mainframe that almost always gives me 2 different dates, but we only need the most recent date.
Here is my query for the view
SELECT dbo.CASES.CaseID, dbo.CASENUMBERS.CaseNumber AS Arrest_Number, dbo.CASENUMBERTYPES.CaseNumTypeCode AS Arrest_NumType,
CASENUMBERS_1.CaseNumber AS JN_Number, CASENUMBERTYPES_1.CaseNumTypeCode AS JN_NumType, dbo.ROLETYPES.RoleTypeDesc,
dbo.ACTORS.SIDNum, dbo.ACTORLOCATIONS.ActorLocDesc, dbo.CHARGENUMBER.ChargeDescription, dbo.DEFCHARGES.OffenseDate,
dbo.fnNameReverse(dbo.ACTORNAMES.LastName, dbo.ACTORNAMES.FirstName, dbo.ACTORNAMES.MiddleName, dbo.ACTORNAMES.Suffix)
AS NameRev, dbo.EVENTS.ev_StartDate AS PreHearingSetDate, dbo.OFFENSELEVELS.OffenseLevelDesc, dbo.CASES.UnitID
FROM dbo.CASES INNER JOIN
dbo.CASENUMBERS ON dbo.CASES.CaseID = dbo.CASENUMBERS.CaseID INNER JOIN
dbo.CASENUMBERTYPES ON dbo.CASENUMBERS.CaseNumTypeID = dbo.CASENUMBERTYPES.CaseNumTypeID INNER JOIN
dbo.CASENUMBERS AS CASENUMBERS_1 ON dbo.CASES.CaseID = CASENUMBERS_1.CaseID INNER JOIN
dbo.CASENUMBERTYPES AS CASENUMBERTYPES_1 ON CASENUMBERS_1.CaseNumTypeID = CASENUMBERTYPES_1.CaseNumTypeID INNER JOIN
dbo.CASEPARTIES ON dbo.CASES.CaseID = dbo.CASEPARTIES.CaseID INNER JOIN
dbo.ROLETYPES ON dbo.CASEPARTIES.RoleTypeID = dbo.ROLETYPES.RoleTypeID AND
dbo.CASEPARTIES.RoleTypeID = dbo.ROLETYPES.RoleTypeID INNER JOIN
dbo.ACTORNAMES ON dbo.CASEPARTIES.ActorNameID = dbo.ACTORNAMES.ActorNameID INNER JOIN
dbo.ACTORS ON dbo.ACTORNAMES.ActorID = dbo.ACTORS.ActorID INNER JOIN
dbo.ACTORLOCATIONS ON dbo.ACTORS.ActorLocationID = dbo.ACTORLOCATIONS.ActorLocationID INNER JOIN
dbo.DEFCHARGESUMMARY ON dbo.CASES.CaseID = dbo.DEFCHARGESUMMARY.CasesCaseID INNER JOIN
dbo.DEFCHARGES ON dbo.DEFCHARGESUMMARY.DefChargeID = dbo.DEFCHARGES.DefChargeID INNER JOIN
dbo.CHARGENUMBER ON dbo.DEFCHARGES.ChargeNumberID = dbo.CHARGENUMBER.ChargeNumberID INNER JOIN
dbo.COURTS ON dbo.CASES.CaseCourtID = dbo.COURTS.CourtID INNER JOIN
dbo.EVENTS ON dbo.CASES.CaseID = dbo.EVENTS.CaseID INNER JOIN
dbo.EVENTTYPES ON dbo.EVENTS.EventTypeID = dbo.EVENTTYPES.EventTypeID INNER JOIN
dbo.OFFENSELEVELS ON dbo.CHARGENUMBER.OffenseLevelID = dbo.OFFENSELEVELS.OffenseLevelID
WHERE (dbo.CASENUMBERTYPES.CaseNumTypeCode = 'NM' OR
dbo.CASENUMBERTYPES.CaseNumTypeCode = 'MC' OR
dbo.CASENUMBERTYPES.CaseNumTypeCode = 'CM' OR
dbo.CASENUMBERTYPES.CaseNumTypeCode = 'JP') AND (CASENUMBERTYPES_1.CaseNumTypeCode = 'JN') AND
(dbo.ROLETYPES.RoleTypeDesc = 'Defendant') AND (dbo.EVENTTYPES.EventTypeDesc = 'PRE-HEARING SET') AND
(dbo.DEFCHARGES.OffenseDate > CONVERT(DATETIME, '2006-01-01 00:00:00', 102))
In the 'PRE-HEARING SET' table is where I receive the two dates. Is there a way to filter out the first date? I just want to show the most recent date.
View 1 Replies
View Related
Mar 15, 2008
Hi everyone,
This is a beginner's question: I know that in order to run a package i need to press ctrl_f5 but i also know that there should be an icon (dimmed green arrow) to do that but i cant find it on the toolbar! I only see the "debug" green arrow. Can anyone help me find the lost "play" (or "run") green arrow ? on which toolbar is it situated ?
Thanks
View 8 Replies
View Related
Nov 21, 2007
I need copy one database from one server into another server.
Both servers have SQLSERVER 2000.
One way is copy the LDF files directly but I need to stop the engine to do that, I€™m sure there are many other ways more efficiently.
I do need an advice.
Thanks in advance
View 10 Replies
View Related
Sep 20, 2006
hi,
does anybody know how to create an identity column in a query without having to use the into clause?
for example, i want to do the following:
select *,identity(int,0,1) as myId
from myTable
but this is not allowed
thank you
View 10 Replies
View Related
Mar 26, 2007
i have a table for storing username and password.
the following are the fields in table
ID -int
UserName-nvarchar(50)
Password-nvarchar(50)
i dont want to have a separate field for id
i want to autincrement them
plz give me an idea
am using SQLServer Express
am new to this field so plz forgive me for this simple question
thanks
Shruthi
View 8 Replies
View Related
Apr 4, 2006
in mysql the primary key has the possibility tu autoincrement herself
can it be done in MS SQL ??? how
View 9 Replies
View Related
Apr 10, 2008
Hi All I am using SQL server Database in one of my table there is a column which is set to Identity=Yes i.e., The ID is increment by one on every insert and if the insertion failed then the id generated goes off then in the next generation it uses new id ..........EXfirst insertion id=1 then in the second insertion if while adding data to other rows if i get some error then the id 2 is not used and when i correct the error and insert it then id=3? can any one give me the solution for this and NextWhen i delete the datafrom the table see the ids are upto 20 and i delete all the records from the table after insertion of new record the id will be 21plese help me in this
View 3 Replies
View Related
Dec 10, 2004
hi,
Is their anybody knows how to make field in Sql Server autoincrement?
pls. help me.
View 3 Replies
View Related
Jun 24, 2008
Hi All,
This may sound quite easy for you, however I am a newbie in SQL.
So I have an identity field, which I wish to increment automatically every time I do an insert. However the starting integer has to be the MAX value from another table.
So for example I am doing an insert in a #temp table
INSERT INTO #temp(name, surname)
SELECT name, surname from table1
Now the personId of the #temp table has to start from the MAX of table2
Ie SELECT MAX(personId) from table2
The SELECT MAX(personId) from table2 can also be NULL, ie the first time I am inserting, so I also have to cater for this scenario.
can anyone help?
Thanks
Johann
View 12 Replies
View Related
Oct 26, 2005
How can I know that a column is auto incremented or not? What are the commands used to know this??
Thanks guys
View 1 Replies
View Related
Dec 12, 2007
Hi all, i am deleting rows of a table and reinserting new ones. This table has an auto increment primary key. what is the function used to set it to zero each time i delete the rows in order to rebegin counting from 1 when i refill the table. Thanks in advance...
View 7 Replies
View Related
Mar 17, 2008
Hi,
I have an existing table (without PK). I want to output my SELECT statement with an auto-increment on the 1st column like this:
# Lastname Firstname Address
1 Obama Clinton xxxxx
2 Hillary xxxx xxxxx
...
Can someone help me on this pls?
Appreciate it.
Thanks
joseph
View 6 Replies
View Related
Apr 7, 2006
I've been searching for an answer a long time now... but nowhere I found a clear solution...
Is it possible to implement autoincrement with SQLexpress edition?
View 8 Replies
View Related
Dec 25, 2006
I created a new table in sql server 2005. Primary key is autoincrement value of 1. But when I insert the row, it increments by 4. It goes like 1, 5, 9 etc..what could be the problem ?how can I correct it? Do I need to reseed it?
Thanks!!
View 14 Replies
View Related
Jul 3, 2000
looking for necessary syntax to alter table id to autoincrement adding identity statement, not sure on syntax for seed an increment, or if it is possible at all.
View 2 Replies
View Related
Sep 14, 1998
I noticed in SQL ODBC API reference that SQLGetTypeInfo would return true for AUTO_INCREMENT if a smallint field is defined as autoincrement. Is there a simple way to set a field autoincrement thru the SQL Server`s front end?
T.G.
View 1 Replies
View Related
Jan 16, 2008
Hey guys,
I have 2 tables:
1. CommandCode( id AutoIncrement_integer, name string )
2. FooCode( FooID integer, CommandCodeID integer)
I have the following stored procedure
PROCEDURE InsertRows( CodeName VARCHAR )
INSERT INTO CommandCode ( name ) VALUES (CodeName)
Now right here I need to INSERT INTO the "FooCode" table using the same ID that was just added to the CommandCode table. How can I retrieve the last inserted autoincrement value for "id" in the CommandTable without doing SELECT id FROM CommandCode WHERE name = CodeName
END PROCEDURE
Is there an easy way to do what I described above? If possible I want it to comply with SQL standards (e.g. no MS SQL specific code)
Thanks!
View 2 Replies
View Related
Jan 19, 2004
Hi all!
Does anyone knows how to get if a column is autoincrement or not, using the DatabaseMetaData in java, or using de JTurbo driver for it?
Is there any other way to figure this out?
:confused:
Thank you very much in advance for any replies.
View 1 Replies
View Related
Apr 15, 2004
Hi All,
i wonder if i can get an bigint autoincrement field where the number begins with the current year + 1 autonumber
Does someone know if it is possible and if yes, how?
Already thanx.
Cheers Wim
View 10 Replies
View Related
Apr 6, 2014
I am creating a trigger in SQL Server that will activate when my Athelete table has something "Inserted"
So far it works except for the fact that it won't insert a null into the Equipment_ID field. I need it to autoincrement, or do the last number + 1...
CREATE TRIGGER TRG_NEW_EQUIPMENT1
ON ATHLETE AFTER INSERT
AS
BEGIN
INSERT INTO Equipment Equipment_ID, Equipment_Model, Equipment_Year, Equipment_Brand, Equipment_Color, Equipment_Condition_Rating)
VALUES ('Big Spin','2016','K2','Blue','5')
END;
GO
View 6 Replies
View Related
Jul 20, 2005
I have a table in my sqlserver 2000 that has a field IDNO. i want thisfield to be my primary key. however i don't want this field to use theautoincrement feature. when i access this table from vb.net and try toadd a record this field is autoincrementing. how can i disable theautoincrement of this field yet serves this as my primary key?thanks in advance
View 4 Replies
View Related
Jul 12, 2006
Hi,
I'm currently writing a small application that is using SQL Server as a back-end database. A part of my database looks something lie the following:
Tables:
Orders(OrderId[int, PK], OrderDescription[varchar] etc...)
OrderLines(OrderId[int, PK, FK], OrderLineId[int, PK], etc...)
What I need to achieve is - everytime that a new line is inserted into an orderlines table part of the primary key will be the OrderId and the OrderLineId should be auto-incremented from 1 for each OrderId in the OrderLines table.
I know i can do this manually in my program, but i'm just wondering if theres a way to achive this in SQL Server?
Thanks,
Nick Goloborodko
View 3 Replies
View Related
May 30, 2007
Hy! I am a beginner in SQLServer and I have to design a database with a lot of tables (30-50 tables). I have to choose a primary key for every table between an autoincrement and a GUID. If I choose autoincrement after an insert statement (from the client) I will have to go back to the server to get the value of the primary key which is a waste of time. On the other hand if I choose a GUID I can create the guid from the client and send him with the other values of the new row to the server and I have not to go back to the server. I am aware of the disk space of a guid field so which is the best for me: GUID or AUTOINCREMENT? Thank you!
View 1 Replies
View Related
Dec 22, 2006
I use Microsoft SQL Server and also I have several tables. One table has ID like PK, and name. ID use autoincrement number mode, and now when I want start form one but not from 156 or like that. I don't know how? And also when I delete all data from table an run my apllication and add something in table, it starts form last number, not from one.
Maybe can I do it from SQL menagement studio?
How I can reset table and start from 1?
View 4 Replies
View Related