Mam za zadanie wymienić sposoby sprawdzenia więzów integralności. Jakie one są? Wiem, że są to warunki, które muszą zostać spełnione. Naruszenie tych zasad musi być anulowane. A jak można to sprawdzić to nie wiem.
Np. zakres danych liczbowych, długość danych dla typu tekstowego, klucz obcy, wartość unikalna...
A to o to chodzi. Myślałem, że jest jakiś inny sposób.
Mam problem jeszcze z tworzeniem tabel.
W tej występuje błąd "Msg 2715, Level 16, State 6, Line 1 Column, parameter, or variable #1: Cannot find data type empid."
Kod jest ze strony https://technet.microsoft.com/en-us/library/aa258255%28v=sql.80%29.aspx
Przypuszczam, że chodzi o wersję SQL Server. Korzystam z 2014.
CREATE TABLE employee
(
emp_id empid
CONSTRAINT PK_emp_id PRIMARY KEY NONCLUSTERED
CONSTRAINT CK_emp_id CHECK (emp_id LIKE
'[A-Z][A-Z][A-Z][1-9][0-9][0-9][0-9][0-9][FM]' or
emp_id LIKE '[A-Z]-[A-Z][1-9][0-9][0-9][0-9][0-9][FM]'),
/* Each employee ID consists of three characters that represent the employee's initials, followed by a five
digit number ranging from 10000 through 99999 and then the employee's gender (M or F).
A (hyphen) - is acceptable for the middle initial. */
fname varchar(20) NOT NULL,
minit char(1) NULL,
lname varchar(30) NOT NULL,
job_id smallint NOT NULL
DEFAULT 1
/* Entry job_id for new hires. */
REFERENCES jobs(job_id),
job_lvl tinyint
DEFAULT 10,
/* Entry job_lvl for new hires. */
pub_id char(4) NOT NULL
DEFAULT ('9952')
REFERENCES publishers(pub_id),
/* By default, the Parent Company Publisher i
s the company
to whom each employee reports. */
hire_date datetime NOT NULL
DEFAULT (getdate())
/* By default, the current system date is ent
ered. */
)
A w której wersji SQL Server istnieje typ empid
? Bo ja pierwsze słyszę, no ale też jakimś SQL guru nie jestem.
Już się zorientowałem i zmieniłem na int.
Zapytania ze strony https://technet.microsoft.com są do uruchomienia na przykładowej bazie danych. Przytoczone przez Ciebie zapytanie należy odpalić na bazie pubs, co jest zresztą napisane zaraz przed tym kawałkiem kodu. Tam też istnieje zdefiniowany typ empid.
This example shows complete table definitions with all constraint definitions for three tables (jobs, employee, and publishers) created in the pubs database.
Wycinek ze skryptu tworzącego bazę pubs:
execute sp_addtype empid ,'char(9)' ,'NOT NULL'