/ Published in: SQL
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
-- create/drop tables CREATE TABLE t_test (a INTEGER PRIMARY KEY ,b VARCHAR(10) ) -- ...with identity CREATE TABLE t_test( id INTEGER IDENTITY PRIMARY KEY, name VARCHAR(10) ); INSERT INTO t_test(name) VALUES ('Andrew'); INSERT INTO t_test(name) VALUES ('Gordon'); SELECT * FROM t_test; -- ... with pkey CREATE TABLE track( album CHAR(10) NOT NULL, dsk INTEGER NOT NULL, posn INTEGER NOT NULL, song VARCHAR(255), PRIMARY KEY (album, dsk, posn) ) -- ... with fkey CREATE TABLE album( id CHAR(10) NOT NULL PRIMARY KEY, title VARCHAR(100), artist VARCHAR(100) ); CREATE TABLE track( album CHAR(10), dsk INTEGER, posn INTEGER, song VARCHAR(255), FOREIGN KEY (album) REFERENCES album(id) ); DROP TABLE t_test -- add/remove columns ALTER TABLE a DROP COLUMN y ALTER TABLE a ADD z INTEGER
URL: http://sqlzoo.net/howto/source/z.dir/tip550066/sqlserver