"Frank Pool" <[EMAIL PROTECTED]> writes:
> I want to create a table with two colums:
>
> One ist the primary key (test_num)
> and the second column sholud contain the value of the primary key (maybe as
> a string) by default.
> How can I define this table in sql ?
>
> CREATE TABLE test_table ("test_num integer primary key AUTOINCREMENT NOT
> NULL, test_name varchar(256) DEFAULT ??? NOT NULL,")
>
> Any ideas ?
With the current version of sqlite3, you can do this.
CREATE TABLE test_table
(
test_num INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
test_name VARCHAR(256)
);
CREATE TRIGGER test_table_tr
AFTER INSERT ON test_table
BEGIN
UPDATE test_table
SET test_name = test_num
WHERE test_num = new.test_num;
END;
INSERT INTO test_table (test_num) VALUES (23);
INSERT INTO test_table (test_num) VALUES (42);
.mode line
SELECT * FROM test_table;
This yields:
test_num = 23
test_name = 23
test_num = 42
test_name = 42
Derrell
-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------