sequence (1 Viewer)

zezo2021

Member
Local time
Today, 16:42
Joined
Mar 25, 2021
Messages
381
1- How can I use the sequence as the default value for a field? or as a computed field

2- Is sequence must be bound to the field by using SQLcode only when creating the tables by using the create table statement
 
Last edited:

zezo2021

Member
Local time
Today, 16:42
Joined
Mar 25, 2021
Messages
381
No to both

what is the answer to the second question
in table design
if I have filed
ID
data type: Int

and
Sequence : Called (Custom Serial)
What properties should I use to use Sequence?
how bound Sequence with this field
 

CJ_London

Super Moderator
Staff member
Local time
Today, 15:42
Joined
Feb 19, 2013
Messages
16,617
Didn’t think there was a second question

but to answer post#3 - whatever properties define the sequence you want - perhaps a date or datetime or maybe an autonumber or geographical location,
 

zezo2021

Member
Local time
Today, 16:42
Joined
Mar 25, 2021
Messages
381
I think you should read here:

If I have understood your question correctly.
second question:
Here is the SQL Code

I know I can create sequences by using SQL Code

but I love using GUI Table Design

my question is
How can I build sequence in design time
(not the IDENTITY )

Code:
CREATE TABLE [MyTable]
(
    [ID] [bigint] PRIMARY KEY NOT NULL DEFAULT (NEXT VALUE FOR dbo.Serial_seq),
    [Title] [nvarchar](64) NOT NULL
);
Code:
Code:


I think it not possible
 

Minty

AWF VIP
Local time
Today, 15:42
Joined
Jul 26, 2013
Messages
10,371
No you can't use it like that, however you could get the next number as part of an insert trigger.

More discussions here
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 10:42
Joined
Feb 19, 2002
Messages
43,293
Do you have an actual reason for using this function? I think the point of it is that it provides a sequence that is used across multiple tables. You insert a row in table 1 and it gets sequence 1, then you insert one in table 2 and it gets 2, then you insert into table 3 and you get a 3. The next row inserted in 1 will have a sequence of 4. Is that what you are actually trying to do?
 

MarkK

bit cruncher
Local time
Today, 07:42
Joined
Mar 17, 2004
Messages
8,181
zezo, the sequence number belongs to the presentation, not to the data. The order of a list is a feature of the list itself, not of its contents. As such, trying to push sequence numbers backwards, from the presentation into the data, is like paddling upstream.

Open your data first, and then add sequence numbers at presentation time. Count the detail sections in your report and display the count. Count rows as you add them to a Listbox. The elegant solution is to number the items in the list, not to number the items in your data.

hth
 

Minty

AWF VIP
Local time
Today, 15:42
Joined
Jul 26, 2013
Messages
10,371
If it's only for use in the presentation layer or to provide some sort of ordering on outputs use the Row_Number() or Rank() SQL functions.
These are designed precisely for that type of task.
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 00:42
Joined
Jan 20, 2009
Messages
12,852
I think you should read here:

If I have understood your question correctly.
The information at the link makes a perfect explanation of a completely pointless use of Sequence in a seriously denormalised design. I feel embarrassed for the author.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 10:42
Joined
Feb 19, 2002
Messages
43,293
The information at the link makes a perfect explanation of a completely pointless use of Sequence in a seriously denormalised design. I feel embarrassed for the author.
I agree. A rational example of usage is always better. I had a lot less trouble understanding trigonometry once our teacher brought a transit into class and took us all out on the football field to show how trig worked in the real world.
 

Users who are viewing this thread

Top Bottom