Example 2: ( Adding Foreign Key Constraint(s) in Table Creation Time )
Create a table called STUDENT with STUD_ID as primary key and STUD_NAME that canط·آ£ط¢آ¢ط£آ¢أ¢â‚¬ع‘ط¢آ¬ط£آ¢أ¢â‚¬â€چط¢آ¢t accept null values and a DEPT_ID column as a forign key to DEPT_ID in DEPT table
Example 3: ( Adding A Constraint After Table Creation Time )
Add a unique constraint on STUD_NAME column after creating table STUDENT as in the previous example
Code:
ALTER TABLE STUDENT ADD CONSTRAINT STUD_NAME_UK UNIQUE ( STUD_NAME);
2.Dropping Constraints
Example : ( Removing a constraint by its name )
Remove the constraint called STUD_NAME_UK from STUDENT table
Code:
ALTER TABLE STUDENT DROP CONSTRAINT STUD_NAME_UK;
3.Adding Indexes
Example :
Add an index on column STUD_NAME IN STUDENT table
Code:
CREATE INDEX STUD_NAME_INDEX ON STUDENT(STUD_NAME);
4.Dropping Indexes
Example : ( Removing an index by its name )
Remove the index called STUD_NAME_INDEX from STUDENT table
Code:
DROP INDEX STUDENT.STUD_NAME_INDEX;
5.Creating Views
Example 1:
Create a view called SALES_RER that conatins all information of employees working as sales representatives
Code:
CREATE VIEW SALES_REP AS SELECT * FROM employees WHERE Title = 'Sales Representative'
Example 2:
Create a view called SUPP_FOR_PROD that contains the names, prices and supplier names for each product
Code:
CREATE VIEW SUPP_FOR_PROD AS SELECT Products.ProductName,Suppliers.ContactName,Products.UnitPrice FROM Products, Suppliers WHERE Products.SupplierID = Suppliers.SupplierID