0% found this document useful (0 votes)
2 views8 pages

Complete Code Lab 4

The document contains SQL commands for managing a database named CompanyDB, including creating and dropping the database and a table named Products. It outlines the structure of the Products table, including various data types and constraints such as primary keys and checks. Additionally, it includes commands to modify the table by adding new columns and altering existing ones.

Uploaded by

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

Complete Code Lab 4

The document contains SQL commands for managing a database named CompanyDB, including creating and dropping the database and a table named Products. It outlines the structure of the Products table, including various data types and constraints such as primary keys and checks. Additionally, it includes commands to modify the table by adding new columns and altering existing ones.

Uploaded by

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

Complete code:

create database CompanyDB;

use CompanyDB;

drop database CompanyDB;

create table Products(


ProductID INT PRIMARY KEY,
ProductName VARCHAR(255),
SupplierID INT,
CategoryID INT,
QuantityPerUnit VARCHAR(255),
UnitPrice DECIMAL(10, 2),
UnitsInStock INT,
UnitsOnOrder INT,
ReorderLevel INT
);

drop table Products;

CREATE TABLE Products (


ProductID INT PRIMARY KEY,
ProductName VARCHAR(255),
SupplierID INT,
CategoryID INT,
QuantityPerUnit VARCHAR(255),
UnitPrice DECIMAL(10, 2),
UnitsInStock INT,
UnitsOnOrder INT,
ReorderLevel INT
);

TRUNCATE TABLE Products;

alter table Products


add UNIQUE (ProductID);

alter table Products


add primary key (ProductID);

alter table Products


add constraint UnitPricechecker CHECK (UnitPrice > 0);

select * from Products;

ALTER TABLE Products


ALTER COLUMN ReorderLevel DEFAULT 10;

ALTER TABLE Products


ADD ExpirationDate DATE;

ALTER TABLE Products


ALTER COLUMN QuantityPerUnit VARCHAR(500);

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy