Skip to main content

SQL Set Operators

SQL Set Operators   Traditional Set Operators: Union Compatibility:     Requirement for the traditional set operators.    Strong requirement.                         - Same number of columns.                         - Each corresponding column is compatible.                         - Positional correspondence.     Apply to similar tables by removing columns first. SQL UNION Example:           Example 1: Retrieve basic data about all university people.                     SELECT FacNo AS PerNo, FacFirstName                                      ...

DDL | Data Definition Language

DDL | Data Definition Language

        DDL or Data Definition Language actually consists of the SQL commands that can be used to define the database schema.

            •CREATE – is used to create the database or its objects (like table, index, function, views, store procedure and triggers).

            •DROP – is used to delete objects from the database.

            •ALTER – is used to alter the structure of the database.

            •TRUNCATE – is used to remove all records from a table, including all spaces allocated for the records are removed.

            •COMMENT – is used to add comments to the data dictionary.

            •RENAME – is used to rename an object existing in the database. 

"CREATE"

        create table mytab( c1 int, c2 varchar(255))


        create table mytab1( C1 int NOT NULL, c2 varchar(255))


        create table mytab2( C1 int NOT NULL UNIQUE, c2 varchar(255))


        create table mytab3( C1 int NOT NULL PRIMARY Key, c2 varchar(255))


        create table mytab4( C1 int , c2 varchar(255), PRIMARY KEY (c1,c2))


        create table mytab5( c1 int, c2 int, c3 varchar(200), PRIMARY KEY (c1,c3), FOREIGN KEY (c2) REFERENCES mytab3(c1))


        create table mytab6( c1 int PRIMARY KEY, c2 varchar(255), c3 varchar(50) DEFAULT 'KARACHI');


        create table mytab7( c1 int PRIMARY KEY, c2 varchar(255), c3 int CHECK (c3>=10) );


create table mytab8( c1 int PRIMARY KEY, c2 varchar(255), c3 int, CHECK (c1>15 AND c3>=10) );




"DROP"


        drop table mytab8 truncate table mytab1


"ALTER"


        ALTER TABLE - ADD Column

        ALTER TABLE mytab1

        ADD c5 int

        ALTER TABLE mytab1

        ADD c6 int

        ADD c7 int


             DROP Columns

            ALTER TABLE mytab1

            DROP column c6

            ALTER TABLE mytab1

            DROP (c5,c2)

            ALTER TABLE mytab1

            modify c7 varchar(100)




Our Official Website : Web Conquerors (https://www.webconquerors.com/) 

Want to get digital services? Contact US

Want to know about our services? Our Services


Comments

Popular posts from this blog

SQL Set Operators

SQL Set Operators   Traditional Set Operators: Union Compatibility:     Requirement for the traditional set operators.    Strong requirement.                         - Same number of columns.                         - Each corresponding column is compatible.                         - Positional correspondence.     Apply to similar tables by removing columns first. SQL UNION Example:           Example 1: Retrieve basic data about all university people.                     SELECT FacNo AS PerNo, FacFirstName                                      ...

CREATE TABLE Syntax

CREATE TABLE Syntax CREATE TABLE <table-name> ( <column-list> [<constraint-list>] ). Column list with data types and optional and inline constraints. Optional external constraint list  CONSTRAINT [ ConstraintName ] <Constraint-Spec>            Primary key            Foreign key            Unique            Check CREATE TABLE Statement Example CREATE TABLE Student            ( StdNo CHAR(11),            StdFirstName VARCHAR(50),            StdLastName VARCHAR(50),            StdCity VARCHAR(50),            StdState CHAR(2),            StdZip CHAR(10),            ...

Query Formulation

Query Formulation   Query Formulation Process: Critical Questions: What tables?           - Columns in result.          - Conditions to test (including join conditions). How to combine the tables?           - Usually join of PK to FK. More complex ways to combine Individual rows or groups of rows?           - Aggregate functions in result.          - Conditions with aggregate functions. University Database Diagram: Summarization and Joins 1:      Example 1: List the number of students enrolled in each 2017 course offering showing the offer number and number of students in the result.                SELECT Offering.OfferNo,                                     COUNT (*) AS NumSt...