0% found this document useful (0 votes)
4 views4 pages

DBMS PRG3 LAB

The document outlines the implementation of a database using SQL Data Definition Language (DDL) with constraints and views. It details various SQL data types, commands for creating, altering, and dropping tables, as well as inserting rows with constraints. The results indicate that all DDL commands were executed successfully.

Uploaded by

joyalprincess
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

DBMS PRG3 LAB

The document outlines the implementation of a database using SQL Data Definition Language (DDL) with constraints and views. It details various SQL data types, commands for creating, altering, and dropping tables, as well as inserting rows with constraints. The results indicate that all DDL commands were executed successfully.

Uploaded by

joyalprincess
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

EX-NO : 3 SQL DATA DEFINITION WITH CONSTRAINTS,

VIEWS
DATE :

AIM:
To implement the database using SQL Data definition with constraints, Views
.
Creation, Altering and Dropping of Tables and Inserting Rows into a Table (Use Constraints
While Creating Tables).

DATA TYPES:-
SQL supports following types of data types.

CHAR (SIZE):-
The CHAR data type stores fixed-length character strings.
When you create a table with a CHAR column, you must specify a string length (in bytes or characters)
between 1 and 2000 bytes for the CHAR column width. The default is 1 byte.

VARCHAR (SIZE):-
The VARCHAR data type is synonymous with the VARCHAR2 data type.

NUMBER (L):-
The NUMBER datatype stores fixed and floating-point numbers. Numbers of virtually any magnitude
can be stored and are guaranteed portable among different systems operating Oracle Database, up to 38
digits of precision.

DECIMAL (L, D):-


Numeric data with total number of digits L and number of digits D after decimal point.

DATE:-
The DATE datatype stores point-in-time values (dates and times) in a table. The DATE datatype stores
the year (including the century), the month, the day, the hours, the Minutes, and the seconds (after
midnight).

LONG:-
Character data of variable length which stores up to 2 Gigabytes of data. (A bigger
version the VARCHAR2 datatype).

INTEGER:-
Integer type of Data. It is actually a synonym for NUMBER(38)

FLOAT:-
FLOAT is a 32-bit, single-precision floating-point number datatype. Each FLOAT 8 value requires 5
bytes, including a length byte.

DOUBLE:-
DOUBLE is a 64-bit, double-precision floating-point number datatype. Each DOUBLE value requires 9
bytes, including a length byte.
Data Definition Language (DDL) Commands: -

Create Table

SQL> CREATE TABLE users (id INT NOT NULL AUTO_INCREMENT, name VARCHAR (50)
NOT NULL, age INT NOT NULL, PRIMARY KEY (id));

SQL> DESCRIBE users;

1. Rename the table users as students

SQL> ALTER TABLE users RENAME TO students


Table altered.

SQL> show tables;

2. Add a new column gender with not null constraints to the existing table students

SQL> ALTER TABLE users ADD gender VARCHAR(10) NOT NULL AFTER AGE;

Table altered.

SQL> DESC students;

To insert a multiple columns inside a table?

ALTER TABLE users ADD city VARCHAR (50) NOT NULL, ADD contact VARCHAR (50) NOT
NULL;
SQL> DESC students;
3. All constraints and views that reference the column are dropped automatically, along
With the column.

SQL> ALTER TABLE students DROP column gender


Table altered.

SQL> DESC students;

4. Rename the column NAME to student_NAME in dept table

SQL> ALTER TABLE students RENAME COLUMN NAME TO student_NAME;


Table altered.

SQL> DESC students;

5. Change the size of column contact with size 25

SQL> ALTER TABLE students MODIFY contact VARCHAR(25) NOT NULL;


;
Table altered.

SQL> DESC students;


6. Delete all records in a table

SQL> TRUNCATE TABLE students;

7. Delete Table

SQL> Drop table students;

Table deleted.

RESULT:
The DDL commands have been executed successfully

You might also like