SQL2008 看看这样的查询语句怎么写???
有个关于权限的表,需要写个查询语句,看源代码:
USE MyDB;GOIF OBJECT_ID('fk_tb1_QX1') IS NOT NULL ALTER TABLE tb2 DROP CONSTRAINT fk_tb1_QX1;GOIF OBJECT_ID('tb1') IS NOT NULLDROP TABLE tb1;GOIF OBJECT_ID('tb2') IS NOT NULLDROP TABLE tb2;GOCREATE TABLE tb1(QX1 VARCHAR(10) NOT NULL ,--一类权限 DSC VARCHAR(50) NULL,--描述 CONSTRAINT pk_tb1_QX1 PRIMARY KEY (QX1) );GOCREATE TABLE tb2( QX VARCHAR(10) NOT NULL ,--详细权限 QXf VARCHAR(10) NULL,--父权限 QX1 VARCHAR(10) NULL,--一类权限 CONSTRAINT pk_tb2_QX PRIMARY KEY (QX), CONSTRAINT fk_tb1_QX1 FOREIGN KEY (QX1) REFERENCES tb1 (QX1));GO--插入数据INSERT INTO tb1 VALUES ('F1a',NULL );INSERT INTO tb1 VALUES ('F1b',NULL );INSERT INTO tb1 VALUES ('F1c',NULL );INSERT INTO tb2 VALUES('F2a',NULL,'F1a');INSERT INTO tb2 VALUES('F2b',NULL,'F1a');INSERT INTO tb2 VALUES('F2c',NULL,'F1a');INSERT INTO tb2 VALUES('F3a','F2a','F1b');INSERT INTO tb2 VALUES('F3b','F2a','F1b');INSERT INTO tb2 VALUES('F3c','F2b','F1c');INSERT INTO tb2 VALUES('F3d','F2b','F1c');