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

SQL Que

The document provides a comprehensive overview of SQL commands for database management, including creating databases and tables, inserting, updating, and deleting data, as well as querying data with various conditions. Additionally, it includes C++ programming examples demonstrating basic algorithms and operations such as reversing a number, checking for prime numbers, and calculating factorials. The content serves as a practical guide for both SQL and C++ programming fundamentals.
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)
2 views12 pages

SQL Que

The document provides a comprehensive overview of SQL commands for database management, including creating databases and tables, inserting, updating, and deleting data, as well as querying data with various conditions. Additionally, it includes C++ programming examples demonstrating basic algorithms and operations such as reversing a number, checking for prime numbers, and calculating factorials. The content serves as a practical guide for both SQL and C++ programming fundamentals.
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

1. What is SQL?

Answer:
SQL stands for Structured Query Language. It is used to manage database.

2. Create database

CREATE DATABASE college;

3. Create table

CREATE TABLE student

id INT,

name VARCHAR(50),

age INT

);

4. Insert data

INSERT INTO student

VALUES(1, 'Prathamesh', 21);

5. Display data

SELECT * FROM student;

6. Display specific column

SELECT name FROM student;

7. Insert multiple records

INSERT INTO student VALUES

(2, 'Rahul', 22),


(3, 'Amit', 20);

8. Update data

UPDATE student

SET age = 23

WHERE id = 1;

9. Delete data

DELETE FROM student

WHERE id = 2;

10. Add column

ALTER TABLE student

ADD city VARCHAR(50);

11. Drop column

ALTER TABLE student

DROP COLUMN city;

12. Rename table

RENAME TABLE student TO students;

13. Where condition

SELECT * FROM student

WHERE age > 20;

14. AND operator

SELECT * FROM student


WHERE age > 20 AND name = 'Prathamesh';

15. OR operator

SELECT * FROM student

WHERE age = 21 OR age = 22;

16. Order by

SELECT * FROM student

ORDER BY age ASC;

17. Count function

SELECT COUNT(*) FROM student;

18. Max function

SELECT MAX(age) FROM student;

19. Min function

SELECT MIN(age) FROM student;

20. Primary key

CREATE TABLE student

id INT PRIMARY KEY,

name VARCHAR(50),

age INT

);

1. Reverse a number

#include <iostream>
using namespace std;

int main()

int num = 1234, reverse = 0;

while(num != 0)

reverse = reverse * 10 + num % 10;

num /= 10;

cout << "Reverse = " << reverse;

2. Check Prime Number

#include <iostream>

using namespace std;

int main()

int n = 7, count = 0;

for(int i=1; i<=n; i++)

if(n%i==0)

count++;

}
if(count==2)

cout<<"Prime";

else

cout<<"Not Prime";

3. Fibonacci Series

#include <iostream>

using namespace std;

int main()

int a=0,b=1,c;

cout<<a<<" "<<b<<" ";

for(int i=1;i<=5;i++)

c=a+b;

cout<<c<<" ";

a=b;

b=c;

4. Palindrome Number

#include <iostream>
using namespace std;

int main()

int n=121, r, sum=0, temp=n;

while(n>0)

r=n%10;

sum=sum*10+r;

n=n/10;

if(temp==sum)

cout<<"Palindrome";

else

cout<<"Not Palindrome";

5. Factorial using function

#include <iostream>

using namespace std;

int fact(int n)

if(n==0)

return 1;

else
return n*fact(n-1);

int main()

cout<<fact(5);

6. Swap without third variable

#include <iostream>

using namespace std;

int main()

int a=10,b=20;

a=a+b;

b=a-b;

a=a-b;

cout<<a<<" "<<b;

7. Find largest in array

#include <iostream>

using namespace std;

int main()
{

int arr[5]={10,50,30,90,20};

int max=arr[0];

for(int i=1;i<5;i++)

if(arr[i]>max)

max=arr[i];

cout<<"Max="<<max;

8. Sum of digits

#include <iostream>

using namespace std;

int main()

int n=123, sum=0;

while(n>0)

sum=sum+n%10;

n=n/10;

cout<<sum;
}

9. Count digits

#include <iostream>

using namespace std;

int main()

int n=12345, count=0;

while(n>0)

count++;

n=n/10;

cout<<count;

10. Armstrong Number

#include <iostream>

using namespace std;

int main()

int n=153,r,sum=0,temp=n;

while(n>0)
{

r=n%10;

sum=sum+r*r*r;

n=n/10;

if(sum==temp)

cout<<"Armstrong";

11. Linear Search

#include <iostream>

using namespace std;

int main()

int arr[5]={10,20,30,40,50};

int key=30;

for(int i=0;i<5;i++)

if(arr[i]==key)

cout<<"Found";

12. Multiplication Table

#include <iostream>
using namespace std;

int main()

int n=5;

for(int i=1;i<=10;i++)

cout<<n*i<<endl;

13. Even numbers 1–50

#include <iostream>

using namespace std;

int main()

for(int i=1;i<=50;i++)

if(i%2==0)

cout<<i<<" ";

14. Simple Calculator

#include <iostream>

using namespace std;

int main()
{

int a=10,b=5;

char op='+';

if(op=='+')

cout<<a+b;

else if(op=='-')

cout<<a-b;

15. Reverse Array

#include <iostream>

using namespace std;

int main()

int arr[5]={1,2,3,4,5};

for(int i=4;i>=0;i--)

cout<<arr[i]<<" ";

You might also like