Get current working directory
notes2
Now we want to select the records with an OrderDate of "2008-11-11" from the table above. We use the following SELECT statement: SELECT * FROM Orders WHERE OrderDate='2008-11-11' SQL constraints are used to specify rules for data in a table. SQL Create ConstraintsConstraints can be specified when the table is created with the CREATE TABLE statement, or after the table is created with the ALTER TABLE statement. SyntaxCREATE TABLE table_name ( column1 datatype constraint, column2 datatype constraint, column3 datatype constraint, .... ); SQL ConstraintsSQL constraints are used to specify rules for the data in a table. Constraints are used to limit the type of data that can go into a table. This ensures the accuracy and reliability of the data in the table. If there is any violation between the constraint and the data action, the action is aborted. Constraints can be column level or table level. Column level constraints apply to a column, and table level constraints apply to the whole table. The following constraints are commonly used in SQL: NOT NULL - Ensures that a column cannot have a NULL value UNIQUE - Ensures that all values in a column are different PRIMARY KEY - A combination of a NOT NULL and UNIQUE. Uniquely identifies each row in a table FOREIGN KEY - Prevents actions that would destroy links between tables CHECK - Ensures that the values in a column satisfies a specific condition DEFAULT - Sets a default value for a column if no value is specified CREATE INDEX - Used to create and retrieve data from the database very quickly SQL NOT NULL ConstraintBy default, a column can hold NULL values. The NOT NULL constraint enforces a column to NOT accept NULL values. This enforces a field to always contain a value, which means that you cannot insert a new record, or update a record without adding a value to this field. SQL NOT NULL on CREATE TABLEThe following SQL ensures that the "ID", "LastName", and "FirstName" columns will NOT accept NULL values when the "Persons" table is created: ExampleCREATE TABLE Persons ( ID int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255) NOT NULL, Age int ); Try it Yourself » SQL NOT NULL on ALTER TABLETo create a NOT NULL constraint on the "Age" column when the "Persons" table is already created, use the following SQL: ALTER TABLE Persons MODIFY Age int NOT NULL; Demak biz not null li constraint ga ega columnga null qiymat o’zlashtira olmaymiz. SQL UNIQUE Constraint The UNIQUE constraint ensures that all values in a column are different. Both the UNIQUE and PRIMARY KEY constraints provide a guarantee for uniqueness for a column or set of columns. A PRIMARY KEY constraint automatically has a UNIQUE constraint. However, you can have many UNIQUE constraints per table, but only one PRIMARY KEY constraint per table. (unique da – biz ustundagi malumotlarni farqli ekanligini taminlaydi. Unique operatorida biz null qiymat bera olamiz.) SQL UNIQUE Constraint on CREATE TABLE The following SQL creates a UNIQUE constraint on the "ID" column when the "Persons" table is created: SQL Server / Oracle / MS Access: CREATE TABLE Persons ( ID int NOT NULL UNIQUE, LastName varchar(255) NOT NULL, FirstName varchar(255), Age int ); Download 0,85 Mb. Do'stlaringiz bilan baham: Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024 ma'muriyatiga murojaat qiling |
kiriting | ro'yxatdan o'tish Bosh sahifa юртда тантана Боғда битган Бугун юртда Эшитганлар жилманглар Эшитмадим деманглар битган бодомлар Yangiariq tumani qitish marakazi Raqamli texnologiyalar ilishida muhokamadan tasdiqqa tavsiya tavsiya etilgan iqtisodiyot kafedrasi steiermarkischen landesregierung asarlaringizni yuboring o'zingizning asarlaringizni Iltimos faqat faqat o'zingizning steierm rkischen landesregierung fachabteilung rkischen landesregierung hamshira loyihasi loyihasi mavsum faolyatining oqibatlari asosiy adabiyotlar fakulteti ahborot ahborot havfsizligi havfsizligi kafedrasi fanidan bo’yicha fakulteti iqtisodiyot boshqaruv fakulteti chiqarishda boshqaruv ishlab chiqarishda iqtisodiyot fakultet multiservis tarmoqlari fanidan asosiy Uzbek fanidan mavzulari potok asosidagi multiservis 'aliyyil a'ziym billahil 'aliyyil illaa billahil quvvata illaa falah' deganida Kompyuter savodxonligi bo’yicha mustaqil 'alal falah' Hayya 'alal 'alas soloh Hayya 'alas mavsum boyicha yuklab olish |