Usuário com melhor resposta
Campo Auto Numeração

Pergunta
-
oi, em uma tabela eu tenho um campo auto numeração, fiz uns testes ai queria zerar o campo (auto numeração) para começar do zero. Tem como ???
eu tenho outras tabelas que estão relacionadas com essa tabela, ai não tem como excluir, ou sei lá.....
Valew.
quarta-feira, 14 de junho de 2006 16:02
Respostas
-
Oi lmlm,
você pode excluir os registros de teste e mandar compactar/reparar o banco de dados. Isto fará a numeração ser restabelecida do início.
Se você usa Access 2003 (e em alguns casos o 2002), a numeração não será restabelecida com a compactação, então você pode executar a seguinte função para forçar o próximo número:
Function ChangeSeed(strTbl As String, strCol As String, lngSeed As Long) As Boolean
'You must pass the following variables to this function.
'strTbl = Table containing autonumber field
'strCol = Name of the autonumber field
'lngSeed = Long integer value you want to use for next AutoNumber.Dim cnn As ADODB.Connection
Dim cat As New ADOX.Catalog
Dim col As ADOX.Column'Set connection and catalog to current database.
Set cnn = CurrentProject.Connection
cat.ActiveConnection = cnnSet col = cat.Tables(strTbl).Columns(strCol)
col.Properties("Seed") = lngSeed
cat.Tables(strTbl).Columns.Refresh
If col.Properties("seed") = lngSeed Then
ChangeSeed = True
Else
ChangeSeed = False
End If
Set col = Nothing
Set cat = Nothing
Set cnn = NothingEnd Function
É necessário fazer referência à biblioteca Microsoft ADO Ext. for security and DDL.
quinta-feira, 15 de junho de 2006 00:13Moderador
Todas as Respostas
-
Bem para tirar a auto-numeração você pode colocar o campo da tabela como outro tipo : numeric e salvar além disso tambem tirar a chave e depois voltar para auto-numerico de novo , se tiver os relacionamentos tera que deletar os mesmo para fazer essa modificação, mas os custos para fazer as vezes não valhe a pena.
Bem qualquer coisa retorne.
quarta-feira, 14 de junho de 2006 18:05 -
Oi lmlm,
você pode excluir os registros de teste e mandar compactar/reparar o banco de dados. Isto fará a numeração ser restabelecida do início.
Se você usa Access 2003 (e em alguns casos o 2002), a numeração não será restabelecida com a compactação, então você pode executar a seguinte função para forçar o próximo número:
Function ChangeSeed(strTbl As String, strCol As String, lngSeed As Long) As Boolean
'You must pass the following variables to this function.
'strTbl = Table containing autonumber field
'strCol = Name of the autonumber field
'lngSeed = Long integer value you want to use for next AutoNumber.Dim cnn As ADODB.Connection
Dim cat As New ADOX.Catalog
Dim col As ADOX.Column'Set connection and catalog to current database.
Set cnn = CurrentProject.Connection
cat.ActiveConnection = cnnSet col = cat.Tables(strTbl).Columns(strCol)
col.Properties("Seed") = lngSeed
cat.Tables(strTbl).Columns.Refresh
If col.Properties("seed") = lngSeed Then
ChangeSeed = True
Else
ChangeSeed = False
End If
Set col = Nothing
Set cat = Nothing
Set cnn = NothingEnd Function
É necessário fazer referência à biblioteca Microsoft ADO Ext. for security and DDL.
quinta-feira, 15 de junho de 2006 00:13Moderador -
Ola Daniel,
Como eu faco isso no sql 2005 ?
at's!
segunda-feira, 26 de junho de 2006 18:20