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

Dbmslab 2

Uploaded by

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

Dbmslab 2

Uploaded by

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

Enter password: ****

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 16

Server version: 8.0.39 MySQL Community Server - GPL

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

------------------------------------------------------------------------------------

mysql> CREATE DATABASE my_database;


ERROR 1007 (HY000): Can't create database 'my_database'; database exists

mysql> use my_database;


Database changed

mysql> create table customers(

-> CustomerID INT PRIMARY KEY , FirstName VARCHAR(50) NOT


NULL , LastName VARCHAR(50) NOT NULL , Email VARCHAR(15) NOT
NULL , PhoneNumber INT NOT NULL

-> );

Query OK, 0 rows affected (0.03 sec)


mysql> describe customers;

mysql> CREATE TABLE products (

-> ProductID INT PRIMARY KEY,

-> ProductName VARCHAR(50) NOT NULL,

-> Price INT NOT NULL,

-> StockQuantity INT,

-> CHECK (Price > 0)

-> );

Query OK, 0 rows affected (0.02 sec)

mysql> describe products;


mysql> CREATE TABLE orders (

-> OrderID INT PRIMARY KEY NOT NULL,

-> CustomerID INT NOT NULL,

-> OrderDate DATE NOT NULL,

-> FOREIGN KEY (CustomerID) REFERENCES


customers(CustomerID)

-> );

Query OK, 0 rows affected (0.18 sec)

mysql> describe orders;

mysql> ALTER TABLE orders


-> ADD CONSTRAINT FK_Customer

-> FOREIGN KEY (CustomerID)

-> REFERENCES customers(CustomerID);

Query OK, 0 rows affected (0.09 sec)

Records: 0 Duplicates: 0 Warnings: 0

mysql> describe orders;

mysql> CREATE TABLE orderdetails (

-> OrderDetailID INT PRIMARY KEY,

-> OrderID INT NOT NULL,

-> ProductID INT NOT NULL,

-> Quantity INT NOT NULL,

-> FOREIGN KEY (OrderID) REFERENCES orders(OrderID),

-> FOREIGN KEY (ProductID) REFERENCES products(ProductID)

-> );

Query OK, 0 rows affected (0.06 sec)


mysql> DESCRIBE orderdetails;

mysql> ALTER TABLE customers

-> add DateOfBirth Date;

Query OK, 0 rows affected (0.03 sec)

Records: 0 Duplicates: 0 Warnings: 0

mysql> describe customers;

mysql> ALTER TABLE customers

-> MODIFY COLUMN PhoneNumber varchar(20)

-> ;
Query OK, 0 rows affected (0.06 sec)

Records: 0 Duplicates: 0 Warnings: 0

mysql> describe customers;

mysql> ALTER TABLE customers

-> DROP COLUMN Email;

Query OK, 0 rows affected (0.02 sec)

Records: 0 Duplicates: 0 Warnings: 0

mysql> describe customers;


mysql> ALTER TABLE customers

-> ADD COLUMN Email varchar(10);

Query OK, 0 rows affected (0.02 sec)

Records: 0 Duplicates: 0 Warnings: 0

mysql> CREATE INDEX idx_email ON Customers (Email);

Query OK, 0 rows affected (0.03 sec)

Records: 0 Duplicates: 0 Warnings: 0

mysql> SHOW INDEX FROM Customers;

mysql> DROP TABLE orderdetails;


Query OK, 0 rows affected (0.02 sec)

mysql> describe orderdetails;

ERROR 1146 (42S02): Table 'my_database.orderdetails' doesn't exist

mysql>

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