forked from thatsabhishek/Coding_Ninjas_DBMS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsqlquery1.sql
43 lines (36 loc) · 1.25 KB
/
sqlquery1.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
Problem Statement :
Write a query for creating a table named People, which contains information given in the table below:
Attribute | Data Type
PID | INT (Primary Key)
LastName | VARCHAR
FirstName | VARCHAR
Address | VARCHAR
City | VARCHAR
Print the Table schema once created as follows:
SELECT table_name, column_name, data_type
FROM information_schema.columns
WHERE table_name = 'your_table'
ORDER BY column_name;
Note - 1: Replace 'your_table' with the actual table name used in the query.
Note - 2: Write keywords of syntax in uppercase alphabets.
Solution:
CREATE TABLE People(
PID INT PRIMARY KEY,
LastName VARCHAR(12),
FirstName VARCHAR(15) NOT NULL,
Address VARCHAR(50),
City VARCHAR(20) );
SELECT table_name, column_name, data_type
FROM information_schema.columns
WHERE table_name = 'People'
ORDER BY column_name;
Output:
+------------+-------------+-----------+
| TABLE_NAME | COLUMN_NAME | DATA_TYPE |
+------------+-------------+-----------+
| people | Address | varchar |
| people | City | varchar |
| people | FirstName | varchar |
| people | LastName | varchar |
| people | PID | int |
+------------+-------------+-----------+