dbms ass
dbms ass
1. Write a SQL statement to create a table with appropriate fields and apply following
integrity constraint on appropriate fields
a. Primary Key
b. Foreign key
c. Unique key
d. Null
e. Check
f. Default
ans:-
Ans;-
To alter the 'Employee' table to add a new column and apply a new constraint to that column,
you can use the following SQL statement:
This SQL statement adds a new column 'hire_date' of type 'DATE' to the 'Employee' table and
applies a constraint 'chk_hire_date' to ensure that the 'hire_date' is not in the future.
3. Write a SQL statement to drop a table.
Ans;-
To drop a table in SQL, we can use the 'DROP TABLE' statement followed by the table name.
Here's the SQL statement to drop a table named 'Employee':
This statement will permanently delete the 'Employee' table and all its associated data. it
cannot be undone.
4. Write a SQL statement to Create a table and do the following using different SQL
commands.
b. Update a record
c. Delete a record
ans;-
example SQL script that creates a table named 'Students', inserts 10 records, updates one of
the records, and then deletes a record:
• We create a table named 'Students' with fields for 'id', 'name', 'age', and 'grade'.
• We insert 10 records into the 'Students' table.
In this SQL script:
Ans;-
example SQL SELECT statement that demonstrates the use of different SQL operators:
These examples demonstrate various SQL operators such as SELECT, DISTINCT, WHERE,
ORDER BY, JOIN, GROUP BY, AND, OR, LIKE, IN, and BETWEEN.
6. Write a SQL select statement with different SQL clauses.
Ans;-
• 'SELECT' clause specifies the columns to be retrieved from the 'Employees' table.
• 'FROM' clause specifies the source table ('Employees').
• 'WHERE' clause filters the rows where the 'department_id' is equal to 100.
• 'ORDER BY' clause sorts the result set based on the 'hire_date' column in descending
order.
• 'LIMIT' clause restricts the number of rows returned to 10.
Ans;-
Ans;-